0

I use the below code to convert the image in the Polar to the Cartesian.


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

Now, I would like to convert the Cartesian to the Polar. I would very much appreciate for any help.

Regards,

J. Cooper

dmg
  • 7,438
  • 2
  • 24
  • 33
  • 2
    Are you asking for the formula on converting Cartesian to Polar? Because if you do know it, converting it to code is the most straight forward thing. – Sipty Feb 10 '15 at 16:23
  • I'm not gonna jump to conclusions and say that this matlab code is taken from [here](https://www.mathworks.com/matlabcentral/newsreader/view_thread/80793), but do you actually know matlab? – dmg Feb 10 '15 at 16:43
  • 1
    Did you not even try Google? http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_polar_coordinates_from_Cartesian_coordinates – rayryeng Feb 10 '15 at 17:24

1 Answers1

0

Thanks for yours answers.

I'm extremely new to MATLAB. I have tried to Google a lot. However, I didn't find the answer. They are opposite to my goal. The above code is from one of the topic I had Google. Actually, I had tried this:

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

But it's not work.