我不太清楚这是你想做的。 所以我在做.
所以给定的图像是我自己的例子,我使用CART2POL将像素的x/y坐标从笛卡尔坐标转换为极坐标。
第一张图显示了点的位置,第二张图显示了原始图像和极坐标图。
请注意,您正在使用“图像处理”工具箱中的WARP函数。 在引擎盖下,使用SURF/SURFACE函数显示纹理贴图的图像。
% load image
路冠;
img=inD2RGB(x,map );
%img=imread(…; % or use any other image
% convertpixelcoordinatesfromcartesiantopolar
[h,w,~]=size(img );
[X,y]=meshgrid(1:w,1:h );
[theta,rho]=cart2pol(x,y );
z=Zeros(Size ) Theta );
% showpixellocations (subsampletogetlessdensepoints )。
xx=x(1:8:end,1:4:end );
YY=Y(1:8:end,1:4:end;
TT=theta(1:8:end,1:4:end );
RR=rho(1:8:end,1:4:end;
subplot(121 ),scatter (xx ) : ),YY ) : ),3,' filled ',axis ij image
subplot(122 ),scatter (TT ) : ),RR (: ),3,' filled ',axis ij square tight
% show images
插图
subplot(121 )、imshow、img )、axis on
subplot(122 ),WARP ) Theta,rho,z,img ),view(2),axis square
编辑
正如我一开始说的,问题不明确。 你必须清楚地描述你想要的映射.
必须考虑转换为极坐标之前原点所在的位置。 前面的示例假设原点基于[ 0,0 ]轴。 和代码没有变化,剩下的
[X,y]=meshgrid((1:w )-floor ) ) w/2 ),(1:h )-floor ) h/2 )
:想将图像(w/2、h/2 )作为原点中心使用时,代替。 为了更好地说明效果,请使用笛卡尔坐标绘制concentric circles源图像,并注意直线极坐标以圆心为原点时如何映射。
编辑
以下是另一个要求注释以极坐标显示图像的示例。 请注意,您正在反向pol2cart上运行映射。
[h,w,~]=size(img );
s=min(h,w )/2;
[rho,theta ]=消息网格(Linspace,s-1,s ),linspace (0,2 * pi ) )
[x,y]=pol2cart(Theta,rho );
z=Zeros(size ) x );
subplot(121 )、im show (img ) )。
subplot(122 )、warp(x ) x、y、z、img )、view(2)、axis square tight off
同样的效果会更好地体现出来。 使用由直线给出的输入图像,看看他们如何在极坐标中映射(垂直线变圆,线和水平线成为从原点开始的起点线)。