Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

display image between four corner points Matlab

Date: 2022-11-17 15:02:35

Suppose I have 4 corner points : (x1, y1) ; (x2, y2) ;(x3, y3) ; (x4, y4) and a rectangular image size (m,n) How do I display the image such that the image when shown has its corners at the four mentioned points. In other words, four corners can control the angle at which the image is rotated (bear in mind the image edges might not be parallel) Thanks! 

Answers: 

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.

Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com