Image remapping without cropping

asked 2013-01-16 03:34:31 -0500

Abid Rahman K gravatar image

I am trying to detect the squares in image below :

image description

And I followed the steps in my answer here : http://dsp.stackexchange.com/a/7526/818

But there is a problem at the end

Explanation :

I already have the centroids of detected squares from step 1 in the previous link (and those detected squares are marked in mask_image below):

enter image description here

I created a grid image as below ( I know centroid values of these squares also) :

enter image description here

I also found which point in grid image to be mapped to corresponding point in mask_image.

With that information, I applied scipy.interpolate.griddata(), and then OpenCV's cv2.remap() function.

And its result is given below :

image description

As you can see, all the squares except the two at center are clipped. It is like, output contain only the region inside a boundary drawn connecting all the centroids of the mask_image.

Scene becomes more worse below :

The case is more worse when the last square (yellow) or any other square in four corners is not detected in first step. Consider last one is not detected. Then below is the result I get and you can see a slant cut at the bottom (marked with yellow color):

enter image description here

Question :

Why remap function not working beyond the points I have given ? And what should I do to remap it without clipping ?

I thought it would work for the full image even if I give some points, which are not at edges.

Expected Output :

Below is the output I expected at the end of my operation. (Region inside red boundary is what I actually got now )

enter image description here

Looking for some good suggestions ...

UPDATE :

I also add the code here. Only remapping part code is added. Full code is too big to be added here :

# ideal - the grid image - http://i.stack.imgur.com/3QudG.png
# centroids - list of centroids of the squares in mask_image - http://i.stack.imgur.com/jh6bQ.png
# match_pts - list of centroids of the squares in grid image corresponding to squares in mask_image
# warped - the final image obtained after remap - http://i.stack.imgur.com/O26ZA.png

grid_x,grid_y = np.meshgrid(np.arange(ideal.shape[1]),np.arange(ideal.shape[0]))
dst = np.array(centroids) 
src = np.array(match_pts) 
grid_z = griddata(dst,src,(grid_x,grid_y),method='cubic')
map_x_32 = grid_z[:,:,0].astype('float32')
map_y_32 = grid_z[:,:,1].astype('float32')
warped = cv2.remap(ideal, map_x_32, map_y_32, cv2.INTER_CUBIC)

Also added the datas like centroids, match_pts etc, so that if someone want to try it out, they can directly use the data instead of finding it from image : gist.github.com/4540887

edit retag flag offensive close merge delete

Comments

Abid Rahman K gravatar imageAbid Rahman K ( 2013-01-16 03:37:10 -0500 )edit