Превратите функцию, деформирующую полигоны, в функцию, деформирующую изображения - PullRequest
1 голос
/ 08 мая 2020

У меня есть эта функция, которая деформирует многоугольник на основе матрицы A. Для этого он хранит вершины многоугольника. Я хотел бы настроить эту функцию, чтобы можно было деформировать изображение вместо многоугольника. Вместо этого необходимо сохранить значение цвета каждого пикселя. Кто-нибудь может мне с этим помочь? Спасибо!

function [polyOut,areaIn,areaOut,detA] = PolygonWarper(polyIn,A)
% Inputs:
% polyIn is an N x 2 matrix (N = # of vertices) for input polygon
% A is an 2 x 2 matrix
% Outputs:%   polyOut has the N x 2  warped polygon vertices
% areaIn is the area of the input polygon
% areaOut is the area of the warped polygon
% detA is the determinant of A



% Uses thisPos to represent the initial polygon
thisPos = polyIn;   

% Makes sure the polygon is roated about its own center instead of the
% center of the screen.
imageCen = mean(polyIn,1);

% The following performs the needed translations in order to create a new
% image.
thisPosR(:,:,1) = thisPos(:,:,1) - imageCen(1);
thisPosG(:,:,2) = thisPos(:,:,2) - imageCen(2);
thisPosB(:,:,3) = thisPos(:,:,3) - imageCen(3);


thisPos = thisPos * A;

thisPosR(:,:,1) = thisPos(:,:,1) + imageCen(1);
thisPosG(:,:,2) = thisPos(:,:,2) + imageCen(2);
thisPosB(:,:,3) = thisPos(:,:,3) + imageCen(3);

polyOut = thisPos;
detA = det(A);

% Both outputs use the x and y coordiantes, where the first column is x and
% the second column is y. 
areaIn = polyarea((polyIn(:,:,1)),(polyIn(:,:,2)));
areaOut = polyarea((polyOut(:,1)),(polyOut(:,2)));

end
...