Display image between four corner points of Matlab

Suppose I have 4 corner points: (x1, y1); (x2, y2); (x3, y3); (x4, y4) and the size of the rectangular image (m, n) How to display the image so that the image, when it was shown, has its angles at the four specified points. In other words, the four corners can control the angle of rotation of the image (remember that the edges of the image may not be parallel) Thank you!

+4
source share
3 answers

You need to warp the image for a generic solution. You can do it as follows:

Read the image first.

img=imread('cameraman.tif');
if size(img,3)==3
   img=rgb2gray(img);

( (x1,y1) ... (x4,y4)), fixedPoints.

movingPoints=[1 1;256 1; 256 256; 1 256] %(x,y) coordinate
fixedPoints=[25 25;250 12;255 200;30 180];

. . .

TFORM = fitgeotrans(movingPoints,fixedPoints,'projective');

, , . 2-D .

R=imref2d(size(img),[1 size(img,2)],[1 size(img,1)]);

, .

imgTransformed=imwarp(imread('cameraman.tif'),R,TFORM,'OutputView',R);

.

imshow(imgTransformed,[]);

, , , .

+5

, , 2 . - -

angle = atan2(y2-y1, x2-x1)*180/pi; %angle between image and axis (in degrees)
B = imrotate(A,angle);              %rotation
+2

, , @Parag, , MATLAB.
: , "" :

udata = [0 1]; 
vdata = [0 1];
fill_color = 128;
org_rect = [0 0;1 0;1 1;0 1];

, fill_color , , . , , :

tform = maketform('projective', org_rect, new_rect);
[out_im,xdata,ydata] = imtransform( in_im, tform, 'bicubic', 'udata', udata, 'vdata', vdata, 'size', size(in_im), 'fill', fill_color);

, (out_im), , data data. , , ( ). , :

imshow(out_im,'XData',xdata,'YData',ydata);

. , .
original Lena RGB
, , .
transformed Lena within the new coordinate system
, , .
transformed Lena without coordinate system
, , : [-1 -2;2 -1;3 3;-3 1]

+2
source

Source: https://habr.com/ru/post/1527229/


All Articles