matlab的图像拼接程序(20210119152549)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
mat lab的图像拼接程
序
-CAL-FENGHAI-(2020YEAR-YICAI) JINGBIAN
ll=imread{,,);%6dTAEuODpAp¥dy2All%6D j u j A
ll=double(ll);
[hl wl dl]=size(ll);%TEOEdl±al2lldU±a>>0dl
I2= imread(n);
I2=double(l2);
[h2 w2 d2]=size(l2);
%show input images and prompt for correspondences figure;subplot( 1,2,1); image(ll/255); axis image; hold on; title(*first input image');
[XI Yl]=ginput(2); %get two points from the usersubplot(l z2,2); image(l2/255); axis image; hold on;
title('sec ond input image*);
[X2 Y2]=ginput(2); %get two points from the user %estimate parameter vector(t);
Z=[X2' Y2'; Y2'・X2'; HOOjOOll]1;
xp=[Xl; Yl];
t=Z\xp; %solve the I in ear system
a=t(l); %=s cos(alpha)
b=t(2);%=s sin(alpha)
tx=t(3);
ty=t(4);
% con struct transformation matrix(T)
T=[a b tx;・b a ty; 0 0 1];
% warp incoming corners to determine the size of the output image(in to out) cp二T*[l 1 w2 w2; 1 h2 1 h2; 1 111];
Xpr=min([cp(l/:)/O]): max([cp(l/:)/wl]);%min x:maxx
Ypr=min([cp(2/:)/0]): max([cp(2/:)/hl]); %min y: max y [Xp/Yp]=ndgrid(Xpr/ Ypr);
[wp hp]=size(Xp); %=size(Yp)
% do backwards transform (from out to in)
X=T\[Xp(:) Yp(:) ones(wp*hp/l)]';%warp
%re-sample pixel values with bilinear interpolation
clear Ip;
xl二reshape(X(b:)Mp,hp)‘;
yl=reshape(X(2/:)/wp/hp)1;
lp(:/:/l)=interp2(l2(:/:/l)/xl/ yl, '♦bilinear*); %red
Ip(:/:/2)=interp2(l2(:/:/2)/xl/ yl, '♦bilinear1);%green lp(:z:/3)=interp2(l2(:/:/3)/xl/ yl, ^bilinear1);%blue
% offset and copy original image into the warped image offset= -rounddmindcpfl/)^]) min([cp(2,:),0])]); lp(l+offset ⑵:hl+offset(2), 1+off set {1): wl+offset (1 )z:); doublefllflihl.liwl,:));
%show the result
figure; image(lp/255); axis image;
title('mosaic image');
ll=double(imread(n));
[hl wl dl]=size(ll);%TEOEdl±aPll6lJ±agl
I2=double(imread(n));
[h2 w2 d2]=size(l2);
%show input images and prompt for correspondences
figure; subplot(l,2z l); image(ll/255); axis image; hold on; title('first input image');
[XI Yl]=ginput(2); %get two points from the user
subplot(122); image(l2/255); axis image; hold on;
title('sec ond input image1);
[X2 Y2]=ginput(2); %get two points from the user
%estimate parameter
vector(t);
Z=[X2' Y2'; Y2'-X2' ;1100;0011]';
xp=[Xl; Yl];
t=Z\xp; %solve the linear system
%%
a=t(l); %=s cos(alpha)
b=t(2); %=s sin(alpha)
tx=t(3);
ty=t(4);
%construct transformation matrix(T)
T=[a b tx;・b a ty; 0 0 1];
%warp incoming corners to determine the size of the output image(in to out) cp=T*[l 1 w2 w2; 1 h2 1 h2;
1 111];
Xpr=min([cp(l/:)/O]):max([cp(l/:)/wl]);% min x: max x
Ypr=min([cp(2/:)/0]):max([cp(2/:)/hl]); %min y :max y (Xp/Yp]=ndgrid(Xpr/ Ypr);
[wp hp]=size(Xp); %=size(Yp) OaAiOD^di® 3d7£-»dN±»E¥po
% do backwards transform(from out to in)
X=T\(Xp(:) Yp(:) ones(wp*hp/ I)]1; %warp
%re-sample pixel values with bilinear interpolation
clear Ip;
xl二reshape(X(:U:), wp, hp)1;
yl=reshape(X(2z:), wp, hp)1; lp(:/:/l)=interp2(l2(:/:/l)/xl, yl,^bilinear1); %red Ip(:/:/2)=interp2(l2(:/:/2)/ xi, yl, '^bilinear'); %green lp(:/:/3)=interp2(l2(:/:,3)/ xl, yl, '^bilinear1);%blue %offset and copy original image into the warped image offset= ・round([min([cp(l,:),0]) min([cp(2,:),0])]);
lp(l+offset⑵:hl+offset(2), l+offset(l):wl+offset(l)#:);
%%
double(ll(l:hl, l:wl/));
%show the result
figure; image(lp/255); axis image;
title('mosaic image');