%%旋转参数限定在-30-30之间
%% load 'building' image
clc
clear
close all;
% 读入8通道图像,若为16通道,程序出错,可通过Photoshop将图像修改为8通道
% im = double(imread('images/building.tif'));
im = double(imread('images/sigma00.tif'));
im = rgb2gray(im);
im = imresize(im,0.25,'bicubic');
%% make the image circularly symmetric
s_im=size(im);
w1=window(@tukeywin,s_im(1),0.25);
w2=window(@tukeywin,s_im(2),0.25)';
w=w1*w2;
im = [zeros(256,s_im(2)+512); zeros(s_im(1),256) im.*w
zeros(s_im(1),256); zeros(256,s_im(2)+512)];
clear w w1 w2;
%% rotate image over 25 degrees
im2 = imrotate(im,25,'bicubic','crop');
% compute the Fourier transforms of the two images
IM = fftshift(abs(fft2(im)));
IM2 = fftshift(abs(fft2(im2)));
%% set values with r<0.1 or r>1 to
zero
s = size(IM)/2;
center=[floor(s(1))+1 floor(s(2))+1]; % compute the image
center
x = ones(s(1)*2,1)*[-1:1/s(2):1-1/s(2)]; % x coordinates of the
pixels
y = [-1:1/s(1):1-1/s(1)]'*ones(1,s(2)*2); % y coordinates of the
pixels
x=x(:);
y=y(:);
[th,ra] = cart2pol(x,y); % polar coordinates of the pixels
IM_ = IM(:);
IM2_ = IM2(:);
IM_(ra<0.1) = 0;
IM2_(ra<0.1) = 0;
IM_(ra>1) = 0; % bandpass filter image A
IM2_(ra>1) = 0; % bandpass filter image B
IM = reshape(IM_,2*s(1),2*s(2));
IM2 = reshape(IM2_,2*s(1),2*s(2));
ss = 0;
%% compute h(alpha) for both images with a precision of 0.5
degrees
precision=0.5;
for i=-90/precision:90/precision % use degree
i_=i*pi*precision/180; % use radian
d=1*pi/180;
v =
(th>i_-d)&(th0.1)&(ra<1);
if
sum(v)>0
h_im(i+90/precision+1) = mean(IM_(v));
h_im2(i+90/precision+1) = mean(IM2_(v));
else
h_im(i+90/precision+1) = 0;
h_im2(i+90/precision+1) = 0;
end
ss = ss +
1;
end
%% plot images
% figure; imshow(IM/100000);
% figure; imshow(IM2/100000);
figure; imshow(IM);
figure; imshow(IM2);
figure; plot([-90:precision:90],h_im,'r',...
[-90:precision:90],h_im2,'b--','LineWidth',2);
xlabel('angle alpha (degrees)'); ylabel('h(alpha)');
le=legend('original image','rotated image');
leg=findobj(le,'type','text');
set(leg,'FontSize',18);
Cc = xcorr(h_im,h_im2);
[h_max,t_max] = max(Cc); % 7601
sample_delay=t_max-ss; % 3600
delay21=sample_delay*(180/(ss-1))
delay22=sample_delay*precision
figure;plot([-180:precision:180],Cc); grid;