2015-02-10 234 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 

但它不工作。

相關問題