Image polar to cartesian and back script issues

4 次查看(过去 30 天)
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,[])

采纳的回答

Gustavo De Camargo
Gustavo De Camargo 2019-6-26
编辑:Gustavo De Camargo 2019-6-26
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by