examples to convert image to polar coordinates do it explicitly - want a slick matrix method

前端 未结 2 1237
天涯浪人
天涯浪人 2020-12-15 01:53

I am trying to convert an image from cartesian to polar coordinates.

I know how to do it explicitly using for loops, but I am looking for something more compact.

2条回答
  •  轮回少年
    2020-12-15 02:49

    I notice that the answer from bla is from polar to cartesian coordinates. However the question is in the opposite direction.

    I=imread('output.png');   %read image
    I1=flipud(I);
    A=imresize(I1,[1024 1024]);
    A1=double(A(:,:,1));
    A2=double(A(:,:,2));
    A3=double(A(:,:,3));  %rgb3 channel to double
    [m n]=size(A1);
    [t r]=meshgrid(linspace(-pi,pi,n),1:m); %Original coordinate
    
    M=2*m;
    N=2*n;
    [NN MM]=meshgrid((1:N)-n-0.5,(1:M)-m-0.5);
    T=atan2(NN,MM);
    R=sqrt(MM.^2+NN.^2);                  
    
    B1=interp2(t,r,A1,T,R,'linear',0);
    B2=interp2(t,r,A2,T,R,'linear',0);
    B3=interp2(t,r,A3,T,R,'linear',0); %rgb3 channel Interpolation
    B=uint8(cat(3,B1,B2,B3));        
    
    subplot(211),imshow(I);  %draw the Original Picture
    subplot(212),imshow(B);  %draw the result
    

提交回复
热议问题