Image polar to cartesian and back script issues
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bray Falls
am 20 Jun. 2019
Kommentiert: Bray Falls
am 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 Kommentare
Akzeptierte Antwort
Gustavo De Camargo
am 26 Jun. 2019
Bearbeitet: Gustavo De Camargo
am 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;
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!