首页 > 解决方案 > 将扭曲多边形的功能变成扭曲图像的功能

问题描述

我有这个函数可以扭曲基于 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

标签: imagematlabimage-processingmatrix-multiplication

解决方案


推荐阅读