Image polar to cartesian and back script issues

조회 수: 5 (최근 30일)
Bray Falls
Bray Falls 2019년 6월 20일
댓글: Bray Falls 2019년 6월 26일
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