Expert Answer:
s:
You need to warp the image for a generalized solution. You can do it as follows:
First, Read the image.
img=imread('cameraman.tif');
if size(img,3)==3
img=rgb2gray(img);
Specify the set of transformed points (in your case, (x1,y1) ... (x4,y4)
), they are fixedPoints
.
movingPoints=[1 1;256 1; 256 256; 1 256] %(x,y) coordinate
fixedPoints=[25 25;250 12;255 200;30 180];
Then, estimate the transformation. I choose projective transformation. You can choose affine as well.
TFORM = fitgeotrans(movingPoints,fixedPoints,'projective');
Since, you want the image to go to the specified corners, you have to specify the output view. It can be done by constructing a reference 2-D image as follows.
R=imref2d(size(img),[1 size(img,2)],[1 size(img,1)]);
Finally, warp the image.
imgTransformed=imwarp(imread('cameraman.tif'),R,TFORM,'OutputView',R);
Show the image.
imshow(imgTransformed,[]);
You should have the corners of your image at the specified points and the box which contains the image will be of the size of the original image.