您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 人事档案/员工关系 > 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');
本文标题:matlab的图像拼接程序
链接地址:https://www.777doc.com/doc-7198625 .html