Image polar to cartesian and back script issues
4 views (last 30 days)
Show older comments
Bray Falls
on 20 Jun 2019
Commented: Bray Falls
on 26 Jun 2019
I'm writing a script to take an image, convert it to polar form about its center, and then convert it back to cartesian. I have a working code to go to polar, and a working code to get to cartesian (except it does not cover all angles). It only seems to cover half of the original image. I can work around this by flipping the polar image and adding the results of the two, but it leaves a line artifact going through the image. I'm wondering how can I make the cartesian conversion cover every angle in the polar image. Here is the code:
img = imread('moon.tif');
%% Cart2pol
[m,n]=size(img);
m0=floor(m/2);
n0=floor(n/2);
% [idx,mp]=gray2double(img,32);
x=(1:n)-(n/2);
y=(1:m)-(m/2);
[xp,yp]=meshgrid(linspace(0,2*pi,1000),linspace(0,400,1000));
[xx,yy]=pol2cart(xp,yp);
img=double(img);
out=interp2(x,y,img,xx,yy);
figure(1)
imshow(out,[])
%% pol 2 cart
x=(1:n)-(n/2);
y=(1:m)-(m/2);
r=linspace(0,-2*pi,1000);
t=linspace(0,400,1000);
[xc,yc]=meshgrid(x,y);
[xx,yy]=cart2pol(xc,yc);
out1=interp2(r,t,out,xx,yy);
out1(isnan(out1))=0;
out1=flipud(out1);
out2=interp2(r,t,fliplr(out),xx,yy);
out2(isnan(out2))=0;
done = out1+out2;
figure(2)
imshow(out1,[])
figure(3)
imshow(out2,[])
figure(4)
imshow(img,[])
figure(5)
imshow(done,[])
0 Comments
Accepted Answer
Gustavo De Camargo
on 26 Jun 2019
Edited: Gustavo De Camargo
on 26 Jun 2019
Try this in your %% pol 2 cart:
x=linspace(n,1,n)-floor(n/2);
y=linspace(m,1,m)-floor(m/2);
r=linspace(-pi,pi,M);
t=linspace(0,400,N);
[xc,yc]=meshgrid(x,y);
[xx,yy]=cart2pol(xc,yc);
out1=interp2(r,t,out,xx,yy);
out1(isnan(out1))=0;
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!