运用matlab进行图形旋转,MATlAB采用互相关方法估算图像的旋转参数

%%旋转参数限定在-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;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值