2015-10-14 30 views
2

旋转后,图像上的点(x,y)需要位于同一图像上。我使用imrotate,imtransform和imwarp来进行图像旋转(下面的代码显示imwarp的实现),但似乎没有一个适合我。输出的旋转图像比原始图像大。任何人都可以建议如何在输出旋转图像上找到相同的点。如何在旋转后找到图像上的一个点?

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; 

enter image description here 虽然代码,如果旋转的图像具有相同的大小,原来的形象工程。但在我的情况下,它会导致原始图像的裁剪。我已经能够在各种论坛上找到这个问题的答案,但似乎没有人为我工作。请回答。

回答

5

呼叫imwarp这样的:

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

refimref2d类型,它包含输出图像的坐标系的关系,以一个“世界坐标系”,的空间引用对象,在该情况下,是输入图像的坐标系。那么你可以这样解释翻译:

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