Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 旋转后如何在图像上找到点?_Matlab_Image Processing_Rotation_Affinetransform - Fatal编程技术网

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

Matlab 旋转后如何在图像上找到点?,matlab,image-processing,rotation,affinetransform,Matlab,Image Processing,Rotation,Affinetransform,旋转图像后,图像上的点(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

旋转图像后,图像上的点(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;

虽然如果旋转后的图像和原始图像大小相同,代码仍然有效。但在我的例子中,它会导致原始图像的裁剪。我已经在各种论坛上找到了这个问题的答案,但似乎没有一个对我有用。请回答。

像这样呼叫
imwarp

[RI, ref] = imwarp(I,tform);
[x1,y1]=transformPointsForward(tform,x,y);
x1 = x1 - ref.XWorldLimits(1);
y1 = y1 - ref.YWorldLimits(1);
ref
是类型为
imref2d
的空间参照对象,其中包含输出图像坐标系与“世界坐标系”之间的关系,在这种情况下,“世界坐标系”是输入图像的坐标系。然后你可以这样解释翻译:

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