相位相關

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章