传入img图片,转成圆形的极坐标图(可以对原图进行裁剪修改)
实心圆环
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