clear;clc
% Image1 = double(imread(['ban-i.bmp'],'bmp'));
% I1 = Image1;%(:,:,2);
%
% Image2 = double(imread(['ban-v.bmp'],'bmp'));
% I2 = Image2;%(:,:,2);
Image1 = imread(['window_view_1'],'jpg');
I1 = double(rgb2gray(Image1));%(:,:,2);
Image2 = imread(['window_view_2'],'jpg');
I2 = double(rgb2gray(Image2));%(:,:,2);
% Image1 = imread(['lenna_right'],'jpeg');
% I1 = double(rgb2gray(Image1));%(:,:,2);
%
% Image2 = imread(['lenna_left'],'jpeg');
% I2 = double(rgb2gray(Image2));%(:,:,2);
L = eye(12,12);
if 1
if 0
xr = 1:size(I1,2);
yr = 1:size(I1,1);
[X,Y] = meshgrid(xr,yr);
cx = mean(xr);
cy = mean(yr);
g = 0.9;
I2 = interp2(X,Y,I1,cx+g*(X-cx),cy+g*(Y-cy));
end
sig = 3*1.8;
H1 = tharris(I1,2*1.5); n1 = size(H1,1); D1 = zeros(n1,12);
H2 = tharris(I2,2*1.5); n2 = size(H2,1); D2 = zeros(n2,12);
rc = H1(:,1:2); % actually column, row
K = find( rc(:,1)-4*sig>0 & rc(:,2)-4*sig>0 & rc(:,1)+4*sig<size(I1,1) & rc(:,2)+4*sig<size(I1,2) );
n1=size(K,1);
K1 = H1(K,:);
for i=1:length(K)
GP = gaussAtPointSP(sig,K1(i,1),K1(i,2),I1);
D1(i,:) = steeredDerivs(GP)';
end
rc = H2(:,1:2); % actually column, row
K = find( rc(:,1)-4*sig>0 & rc(:,2)-4*sig>0 & rc(:,1)+4*sig<size(I2,1) & rc(:,2)+4*sig<size(I2,2) );
n2=size(K,1); K2 = H2(K,:);
for i=1:length(K)
GP = gaussAtPointSP(sig,K2(i,1),K2(i,2),I2);
D2(i,:) = steeredDerivs(GP)';
end
end
f1 = 1:n1; %find(K1(:,3)>1e4);
Hmod = K1(f1,[2 1]);
f2 = 1:n2; %find(K2(:,3)>1e4);
Hobs = K2(f2,[2 1]);
Vmod = (L*D1(f1,:)')';
neighMod = neighbours(Hmod,5);
Vobs = (L*D2(f2,:)')';
neighObs = neighbours(Hobs,5);
thresh =1; voteList = matches(Vmod, neighMod, Vobs, neighObs, thresh),
Imod = I1;
Iobs = I2;
% display several correspondences as a line between two images on same frame
Itot = [Iobs Imod];
size(Itot),
w = size(Iobs,2),
figure(2);
set(2,'Name','Image 1');
imshow(uint8(Image1));
hold on,plot(H1(:,2),H1(:,1),'r+');
hold on,plot(Hmod(:,1),Hmod(:,2),'bo');
figure(3);
set(3,'Name','Image 2');
imshow(uint8(Image2));
hold on,plot(H2(:,2),H2(:,1),'r+');
hold on,plot(Hobs(:,1),Hobs(:,2),'bo');
figure(1); set(1,'Name','Matches'); imagesc(Itot); colormap gray;
hold on, plot(Hobs(:,1),Hobs(:,2),'b+', Hmod(:,1)+w,Hmod(:,2),'r+');
chnk = size(voteList,1), % maximum number of correspondences to show at once
h = 0;
for i=1:chnk:size(voteList,1)
if (h), set(h,'Visible','off'); end
m = min(i+chnk-1,size(voteList,1));
vm = voteList(i:m,2);
vo = voteList(i:m,1);
hold on, h=plot([Hobs(vo,1) Hmod(vm,1)+w]',[Hobs(vo,2) Hmod(vm,2)]');%,'r-');
%pause;
end
m=0;
RP = [H1(voteList(1,2),2) H1(voteList(1,2),1);
H1(voteList(2,2),2) H1(voteList(2,2),1);
H1(voteList(3,2),2) H1(voteList(3,2),1);
H1(voteList(4,2),2) H1(voteList(4,2),1);];
LP = [H2(voteList(1,1),2) H2(voteList(1,1),1);
H2(voteList(2,1),2) H2(voteList(2,1),1);
H2(voteList(3,1),2) H2(voteList(3,1),1);
H2(voteList(4,1),2) H2(voteList(4,1),1);];
LP, RP,
M0=computeM0(LP,RP);
M0(9,1) = 1;
MM=reshape(M0,3,3);
MM=MM';
%MM=[1 0 0;0 1 200;0 0 1;];
[q,r] = size(I1);
[s,t] = size(I2);
C(:,:,:)=Image1(:,:,:);
for i=1:s
for j=1:t
ii=round((i*MM(1,1)+j * MM(1,2)+1 * MM(2,3)) /(MM(3,1)*i + MM(3,2)*j + MM(3,3)));
jj=round((i*MM(2,1)+j*MM(2,2)+1*MM(1,3))/(MM(3,1)*i+MM(3,2)*j+MM(3,3)));
if((ii>1) & (jj>1))
C(ii,jj,:)=Image2(i,j,:);
end
end
end
figure(5);
set(5,'Name','Mosaic');
imshow(uint8(C))
- 1
- 2
- 3
- 4
- 5
- 6
前往页