简体   繁体   English

旋转后如何在图像上找到一个点?

[英]How to find a point on image after rotation?

A point(x,y) on image need to be located on same image after rotating it. 旋转后,图像上的点(x,y)需要位于同一图像上。 I have used imrotate, imtransform and imwarp for rotation of image (Code below show implementation of imwarp), but none seems to work for me. 我使用了imrotate,imtransform和imwarp来旋转图像(下面的代码显示了imwarp的实现),但似乎没有一个对我有用。 The output rotated image is larger than original image. 输出旋转图像大于原始图像。 Can anybody advise how to locate the same point on output rotated image. 任何人都可以建议如何在输出旋转图像上找到相同的点。

close all;
I=imread('P.png');
x=339;
y=317;

subplot(2,2,1);
imshow(I),title('Original Image');    
hold on;
plot(x,y,'ro');
hold off;
theta=5;
tform = affine2d([cosd(theta) -sind(theta) 0;sind(theta) cosd(theta) 0; 0 0 1])
RI = imwarp(I,tform);
[x1,y1]=transformPointsForward(tform,x,y);
subplot(2,2,2);
imshow(RI),title('Rotated Image');    
hold on;
plot(x1,y1,'ro');
hold off;

在此输入图像描述 Though the code works if rotated image have same size as original image. 虽然旋转图像与原始图像具有相同的大小,但代码仍然有效。 but in my case it leads to cropping of original image. 但在我的情况下,它会导致裁剪原始图像。 I have been able to find answer to this question on various forums, but none seems to be working for me. 我已经能够在各种论坛上找到这个问题的答案,但似乎没有一个对我有用。 Kindly answer it. 请回答。

Call imwarp like this: 像这样打电话给imwarp

[RI, ref] = imwarp(I,tform);

ref is a spacial referencing object of type imref2d , which contains the relationship of the output image's coordinate system to a "world coordinate system", which, in this case, is the coordinate system of the input image. refimref2d类型的空间参考对象,它包含输出图像的坐标系与“世界坐标系”的关系,在这种情况下,它是输入图像的坐标系。 Then you can account for the translation like this: 然后您可以像这样说明翻译:

[x1,y1]=transformPointsForward(tform,x,y);
x1 = x1 - ref.XWorldLimits(1);
y1 = y1 - ref.YWorldLimits(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM