Matlab 图像转极坐标系

实心圆环

imgVP1=flip(imgVP1,1);  % 水平翻转

polarVP1=polarVolinPlot(imgVP1); % 调用函数
空心圆环

[m,n,~]=size(imgVP2);

% 填充空心部分

for i=m:m+300

    for j=1:n

        imgVP2(i,j,:)=[255,255,255];

    end

end

imgVP2=flip(imgVP2,1);

polarVP2=polarVolinPlot(imgVP2);
 

function [polarImg] = polarImg(img0)
% polarImg
Rimg0=double(img0(:,:,1));
Gimg0=double(img0(:,:,2));
Bimg0=double(img0(:,:,3));
[m,n]=size(Rimg0);
%原图坐标
[t,r]=meshgrid(linspace(-pi,pi,n),1:m);
M=2*m;N=2*n;
[NA,MA]=meshgrid((1:N)-n-0.5,(1:M)-m-0.5);
T=atan2(NA,MA);
R=sqrt(MA.^2+NA.^2);%变换坐标
Rpolar=interp2(t,r,Rimg0,T,R,'linear',0);
Gpolar=interp2(t,r,Gimg0,T,R,'linear',0);
Bpolar=interp2(t,r,Bimg0,T,R,'linear',0);
polarImg=uint8(cat(3,Rpolar,Gpolar,Bpolar));
polarImg=imrotate(polarImg, -90);
% 图片裁剪
if M<N
polarImg = imcrop(polarImg,[0,(N-M)/2,M,M]);
else
polarImg = imcrop(polarImg,[0,(M-N)/2,N,N]);
end
end
--------------------- 

posted @ 2019-07-08 21:35  水至清明  阅读(407)  评论(0编辑  收藏  举报