相位相关

pattern0=abs(pattern0);
if length(size(pattern0))>2
    pattern=rgb2gray(pattern0);
else
    pattern=pattern0;
end
I2=pattern;
load I1.mat;%当旋转角度为0的基准图
[m,n]=size(I1);
%fft
F1=fftshift(fft2(I1));
F2=fftshift(fft2(I2));
%高通滤波
d0=30;
h=zeros(m,n);
for i=1:m
    for j=1:n
        d=sqrt((i-m/2)^2+(j-n/2)^2);
        if d>d0
            h(i,j)=1;
        end
    end
end
I11=h.*abs(F1);
I21=h.*abs(F2);
%显示
% figure,subplot 321,imshow(I1,[]);
% subplot 322,imshow(I2,[]);
% subplot 323,imshow(F1,[]);
% subplot 324,imshow(F2,[]);
% subplot 325,imshow(I11,[]);
% subplot 326,imshow(I21,[]);
%极坐标变换
Ntheta = 512;
Rtheta = [0 pi];
Nrho = 512;
Rrho = [1 min(m,n)];
%Rrho = [1 sqrt((sizeX/2)^2+(sizeY/2)^2)];

theta = linspace(Rtheta(1), Rtheta(2), Ntheta+1); theta(end)=[];
rho = logspace(log10(Rrho(1)), log10(Rrho(2)), Nrho);
xx = rho'*cos(theta) + n/2;
yy = rho'*sin(theta) + m/2;
mask= (xx>n) | (xx<1) | (yy>m) | (yy<1);
%插值
L1 = interp2(I11(:,:,1), xx, yy, 'cubic');
L1(mask) = 0;
L2 = interp2(I21(:,:,1), xx, yy, 'cubic');
L2(mask) = 0;
%显示
% figure,subplot 121,imshow(L1,[]);
% subplot 122,imshow(L2,[]);
%相位相关
FL1 = fft2(L1);
FL2 = fft2(L2);

FCross = exp(1i*(angle(FL1)-angle(FL2)));
FPhase = real(ifft2(FCross));
[x,y]=find(FPhase==max(FPhase(:)));
theta1=180-theta(y)*180/pi;%需要判断有可能theta1=theta(y)*180/pi

猜你喜欢

转载自blog.csdn.net/qq_41244435/article/details/86541572