image - 将扭曲多边形的功能变成扭曲图像的功能
问题描述
我有这个函数可以扭曲基于 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
解决方案
推荐阅读
- vue.js - 如何为 Vue 项目指定有效的入口点/文件?
- c# - c# switch/case额外变量语法
- android - 如何缓存所有图像而不用壁画显示它们?
- node.js - IBM Cloud DevOps 持续交付管道节点版本过低
- c++ - 在处理智能指针之前,我正在学习原始指针。以下代码是否被认为是不好的做法?
- java - 使用方法重写标签
- python - 如何处理密码中的@符号 - sqlalchemy
- php - 设置与值相关的变量
- python - Telegram Bot API media_group_id 在 send_media_group 方法中的使用
- java - 在仍然有大量可用 RAM 的 docker swarm 上运行时,Java 运行时环境的内存不足