2015-02-10 239 views
0

我使用下面的代码将极坐标图像转换为笛卡尔坐标系。如何将笛卡尔图像转换为极坐标图像


for ii=1:500; 
    for jj=1:500 
     phase(ii,jj)=((ii-250)^2/1000+(jj-250)^2/1000); 
    end 
end 
Cartesian=cos(phase); 
[imrow,imcol]=size(Cartesian); 

% choose the center of the image 
rcent=250; 
ccent=250; 

rmax=sqrt((imrow-rcent)^2+(imcol-ccent)^2); 
%prepare the gridspace in the transformed coordinate 
[r,theta]=meshgrid(linspace(0,rmax,imrow),linspace(0,2*pi,imcol)); 
%corresponding locations in the original coordinate 
x=r.*cos(theta)+ccent; 
y=r.*sin(theta)+rcent; 

%sample original fringe pattern using interpolation 
Polar=interp2(Cartesian,x,y); 

subplot(1,2,1); imagesc(Cartesian) ; axis square 
subplot(1,2,2); imagesc(Polar) ; axis square 

现在,我想笛卡尔转换成极。我非常感谢任何帮助。

问候,

J.库珀

+2

您是否要求将Cartesian转换为Polar的公式?因为如果你知道它,将它转换为代码是最直接的事情。 – Sipty 2015-02-10 16:23:17

+0

我不会跳到结论,并说这个matlab代码取自[这里](https://www.mathworks.com/matlabcentral/newsreader/view_thread/80793),但是你真的知道matlab吗? – dmg 2015-02-10 16:43:10

+1

你甚至没有试过Google吗? http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_polar_coordinates_from_Cartesian_coordinates – rayryeng 2015-02-10 17:24:26

回答

0

谢谢你的答案。

我对MATLAB非常陌生。我曾试图谷歌很多。但是,我没有找到答案。他们与我的目标相反。以上代码来自我使用Google的主题之一。其实,我曾试过这个:

r1 = sqrt(x.^2+y.^2); 
theta1 = atan(y./x); 
Cartesian2 = interp2(Polar,r1,theta1); 

subplot(1,3,1); imagesc(Cartesian) ; axis square 
subplot(1,3,2); imagesc(Polar) ; axis square 
subplot(1,3,3); imagesc(Cartesian2) ; axis square 

但它不工作。

相关问题