Image polar to cartesian and back script issues

3 ビュー (過去 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;
  1 件のコメント
Bray Falls
Bray Falls 2019 年 6 月 26 日
Works perfect! Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by