matlab的图像拼接程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

I1=imread('left.jpg');%ÒÔÏÂËùÓеĵ¥ÒýºÅ¶¼Óиü¸ÄI1=double(I1);[h1w1d1]=size(I1);%ÏÈÓÉd1±äΪl1ÔÙ±ä»Ød1I2=imread('right.jpg');I2=double(I2);[h2w2d2]=size(I2);%showinputimagesandpromptforcorrespondencesfigure;subplot(1,2,1);image(I1/255);axisimage;holdon;title('firstinputimage');[X1Y1]=ginput(2);%gettwopointsfromtheusersubplot(1,2,2);image(I2/255);axisimage;holdon;title('secondinputimage');[X2Y2]=ginput(2);%gettwopointsfromtheuser%estimateparametervector(t);Z=[X2'Y2';Y2'-X2';1100;0011]';xp=[X1;Y1];t=Z\xp;%solvethelinearsystema=t(1);%=scos(alpha)b=t(2);%=ssin(alpha)tx=t(3);ty=t(4);%constructtransformationmatrix(T)T=[abtx;-baty;001];%warpincomingcornerstodeterminethesizeoftheoutputimage(intoout)cp=T*[11w2w2;1h21h2;1111];Xpr=min([cp(1,:),0]):max([cp(1,:),w1]);%minx:maxxYpr=min([cp(2,:),0]):max([cp(2,:),h1]);%miny:maxy[Xp,Yp]=ndgrid(Xpr,Ypr);[wphp]=size(Xp);%=size(Yp)%dobackwardstransform(fromouttoin)X=T\[Xp(:)Yp(:)ones(wp*hp,1)]';%warp%re-samplepixelvalueswithbilinearinterpolationclearIp;xI=reshape(X(1,:),wp,hp)';yI=reshape(X(2,:),wp,hp)';Ip(:,:,1)=interp2(I2(:,:,1),xI,yI,'*bilinear');%redIp(:,:,2)=interp2(I2(:,:,2),xI,yI,'*bilinear');%greenIp(:,:,3)=interp2(I2(:,:,3),xI,yI,'*bilinear');%blue%offsetandcopyoriginalimageintothewarpedimageoffset=-round([min([cp(1,:),0])min([cp(2,:),0])]);Ip(1+offset(2):h1+offset(2),1+offset(1):w1+offset(1),:);double(I1(1:h1,1:w1,:));%showtheresultfigure;image(Ip/255);axisimage;title('mosaicimage');I1=double(imread('left.jpg'));[h1w1d1]=size(I1);%ÏÈÓÉd1±äΪl1ÔÙ±äg1I2=double(imread('right.jpg'));[h2w2d2]=size(I2);%showinputimagesandpromptforcorrespondencesfigure;subplot(1,2,1);image(I1/255);axisimage;holdon;title('firstinputimage');[X1Y1]=ginput(2);%gettwopointsfromtheusersubplot(1,2,2);image(I2/255);axisimage;holdon;title('secondinputimage');[X2Y2]=ginput(2);%gettwopointsfromtheuser%estimateparametervector(t);Z=[X2'Y2';Y2'-X2';1100;0011]';xp=[X1;Y1];t=Z\xp;%solvethelinearsystem%%a=t(1);%=scos(alpha)b=t(2);%=ssin(alpha)tx=t(3);ty=t(4);%constructtransformationmatrix(T)T=[abtx;-baty;001];%warpincomingcornerstodeterminethesizeoftheoutputimage(intoout)cp=T*[11w2w2;1h21h2;1111];Xpr=min([cp(1,:),0]):max([cp(1,:),w1]);%minx:maxxYpr=min([cp(2,:),0]):max([cp(2,:),h1]);%miny:maxy[Xp,Yp]=ndgrid(Xpr,Ypr);[wphp]=size(Xp);%=size(Yp)ÕâÀïÓиö¡®³ö´í£¬Òѱ»È¥µô%dobackwardstransform(fromouttoin)X=T\[Xp(:)Yp(:)ones(wp*hp,1)]';%warp%re-samplepixelvalueswithbilinearinterpolationclearIp;xI=reshape(X(1,:),wp,hp)';yI=reshape(X(2,:),wp,hp)';Ip(:,:,1)=interp2(I2(:,:,1),xI,yI,'*bilinear');%redIp(:,:,2)=interp2(I2(:,:,2),xI,yI,'*bilinear');%greenIp(:,:,3)=interp2(I2(:,:,3),xI,yI,'*bilinear');%blue%offsetandcopyoriginalimageintothewarpedimageoffset=-round([min([cp(1,:),0])min([cp(2,:),0])]);Ip(1+offset(2):h1+offset(2),1+offset(1):w1+offset(1),:);%%double(I1(1:h1,1:w1,:));%showtheresultfigure;image(Ip/255);axisimage;title('mosaicimage');

1 / 2
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功