This is a continuation of this question : Finding Squares in Image
I followed the steps in my answer there : https://dsp.stackexchange.com/a/7526/818, And I got the answer as given below :
But at the end of that answer, I have explained a problem, and that is my question.
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):
I created a grid image as below ( I know their centroid values also) :
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 :
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):
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 got actually got now )
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 - https://i.stack.imgur.com/3QudG.png
# centroids - list of centroids of the squares in mask_image - https://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 - https://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