To undistort a single image, define
movingPoints as a 2-by-16 matrix
that describes an array of corners in image. Then copy the values to
fixedPoints and manipulate the coordinates manually.
In my case, the input image is significantly distorted, similiar like a fish eye filtered image.
Neither affine, nor projective image warping would undistort the image.
cp2tform function with the
can satisfy such requirement. Here is how I solve my problem with it.
t = cp2tform(movingPoints,fixedPoints,'polynomial'); J = imtransform(I,t,'size',size(I),... 'xdata',double([1,size(I,2)]),... 'ydata',double([1,size(I,1)])); subplot(121),imshow(I); hold on; plot(movingPoints(:,1),movingPoints(:,2),'r.'); hold off; subplot(122),imshow(J); hold on; plot(movingPoints(:,1),movingPoints(:,2),'r.'); plot(fixedPoints(:,1),fixedPoints(:,2),'b.'); hold off;
The red dots in the above image are
movingPoints, which comes from the
feature points on the original image. And the blue dots are where I want then to be.
By solving the corrrespondce problem, I can get exactly what I want.