gpt4 book ai didi

matlab - 四边形到矩形变换

转载 作者:行者123 更新时间:2023-12-02 09:59:41 24 4
gpt4 key购买 nike

我想将四边形图像转换为我知道这些顶点的矩形图像。例如,在下图中,我知道坐标 (X1,Y1) ~ (X4,Y4) 和 (x1,y1) ~ (x2,y2) 并且我想将其转换为矩形。如何获得矩形图像中的(x,y)坐标与四边形图像中的(X,Y)坐标相对应?

 ____> Y             ____> y            
| |
| |
V V
X x

(X1,Y1) (X2,Y2) (x1,y1) (x1,y2)
________ _________
/ .(X,Y) \ => | .(x,y) |
/__________\ |_________|
(X3,Y3) (X4,Y4) (x2,y1) (x2,y2)

最佳答案

如果这应该是透视变换,那么您要查找的术语是 homography 。也许这些链接中的 Matlab 函数可以满足您的需求:

http://www.csse.uwa.edu.au/~pk/research/matlabfns/#projective

http://www.robots.ox.ac.uk/~vgg/hzbook/code/

评论后编辑:好的,所以我用 Mathematica 解了方程。如果您定义(为了可读性)

M=(x-x1)/(x2-x1)

N=(y-y1)/(y2-y1),

那么这对解决方案就相当笨拙

{M -> -(X1 Y - X3 Y + X4 Y - X Y1 - X4 Y1 + X Y2 - 2 X1 Y2 + X3 Y2 + 
X Y3 - X2 (Y - 2 Y1 + Y3) - X Y4 +
X1 Y4 + \[Sqrt](4 (X3 (-Y + Y1) + X1 (Y - Y3) +
X (-Y1 + Y3)) (-(X3 - X4) (Y1 - Y2) + (X1 - X2) (Y3 -
Y4)) + (X4 (-Y + Y1) + X3 (Y - 2 Y1 + Y2) +
X2 (Y - Y3) - X1 (Y - 2 Y3 + Y4) +
X (Y1 - Y2 - Y3 + Y4))^2))/(2 (-(X2 - X4) (Y1 -
Y3) + (X1 - X3) (Y2 - Y4))),
N -> -(-X2 Y - X3 Y + X4 Y - X Y1 + 2 X3 Y1 - X4 Y1 + X Y2 - X3 Y2 +
X Y3 + X2 Y3 - X Y4 +
X1 (Y - 2 Y3 +
Y4) - \[Sqrt](4 (X3 (-Y + Y1) + X1 (Y - Y3) +
X (-Y1 + Y3)) (-(X3 - X4) (Y1 - Y2) + (X1 - X2) (Y3 -
Y4)) + (X4 (-Y + Y1) + X3 (Y - 2 Y1 + Y2) +
X2 (Y - Y3) - X1 (Y - 2 Y3 + Y4) +
X (Y1 - Y2 - Y3 + Y4))^2))/(2 (-(X3 - X4) (Y1 -
Y2) + (X1 - X2) (Y3 - Y4)))}

{M -> -(X1 Y - X3 Y + X4 Y - X Y1 - X4 Y1 + X Y2 - 2 X1 Y2 + X3 Y2 + 
X Y3 - X2 (Y - 2 Y1 + Y3) - X Y4 +
X1 Y4 - \[Sqrt](4 (X3 (-Y + Y1) + X1 (Y - Y3) +
X (-Y1 + Y3)) (-(X3 - X4) (Y1 - Y2) + (X1 - X2) (Y3 -
Y4)) + (X4 (-Y + Y1) + X3 (Y - 2 Y1 + Y2) +
X2 (Y - Y3) - X1 (Y - 2 Y3 + Y4) +
X (Y1 - Y2 - Y3 + Y4))^2))/(2 (-(X2 - X4) (Y1 -
Y3) + (X1 - X3) (Y2 - Y4))),
N -> -(-X2 Y - X3 Y + X4 Y - X Y1 + 2 X3 Y1 - X4 Y1 + X Y2 - X3 Y2 +
X Y3 + X2 Y3 - X Y4 +
X1 (Y - 2 Y3 +
Y4) + \[Sqrt](4 (X3 (-Y + Y1) + X1 (Y - Y3) +
X (-Y1 + Y3)) (-(X3 - X4) (Y1 - Y2) + (X1 - X2) (Y3 -
Y4)) + (X4 (-Y + Y1) + X3 (Y - 2 Y1 + Y2) +
X2 (Y - Y3) - X1 (Y - 2 Y3 + Y4) +
X (Y1 - Y2 - Y3 + Y4))^2))/(2 (-(X3 - X4) (Y1 -
Y2) + (X1 - X2) (Y3 - Y4)))}

请注意,唯一的区别是 Srqt 之前的符号。

现在只需重新构造上面MN的定义即可得到x,yx=M*(x2-x1)+x1y=N*(y2-y1)+y1

关于matlab - 四边形到矩形变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com