收藏 分享(赏)

matlab的图像拼接程序.doc

上传人:HR专家 文档编号:11468424 上传时间:2020-05-09 格式:DOC 页数:2 大小:29KB
下载 相关 举报
matlab的图像拼接程序.doc_第1页
第1页 / 共2页
matlab的图像拼接程序.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、I1= imread(left.jpg);%I1=double(I1);h1 w1 d1=size(I1);%d1l1d1I2= imread(right.jpg);I2=double(I2);h2 w2 d2=size(I2);%show input images and prompt for correspondences figure;subplot(1,2,1); image(I1/255); axis image; hold on;title(first input image);X1 Y1=ginput(2); %get two points from the usersubplo

2、t(1,2,2);image(I2/255); axis image; hold on;title(second input image);X2 Y2=ginput(2); %get two points from the user %estimate parameter vector(t);Z=X2 Y2; Y2-X2; 1 1 0 0 ; 0 0 1 1 ;xp=X1; Y1;t=Zxp; %solve the linear system a=t(1); %=s cos(alpha)b=t(2);%=s sin(alpha)tx=t(3);ty=t(4);% construct trans

3、formation 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*1 1 w2 w2; 1 h2 1 h2; 1 1 1 1;Xpr=min(cp(1,:),0): max(cp(1,:),w1);%min x:max xYpr=min(cp(2,:),0): max(cp(2,:),h1); %min y: max yXp,Yp=ndgrid(Xpr, Ypr);wp hp=size(Xp); %=size(Y

4、p)% do backwards transform (from out to in)X=TXp(:) Yp(:) ones(wp*hp,1); %warp%re-sample pixel values with bilinear interpolationclear Ip;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(:,

5、:,3)=interp2(I2(:,:,3),xI, yI, *bilinear); %blue% offset and copy original image into the warped imageoffset= -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,:);%show the resultfigure; image(Ip/255); axis image;title(mosaic image);I1=

6、double(imread(left.jpg);h1 w1 d1=size(I1);%d1l1g1I2=double(imread(right.jpg);h2 w2 d2=size(I2);%show input images and prompt for correspondencesfigure; subplot(1,2,1); image(I1/255); axis image; hold on;title(first input image);X1 Y1=ginput(2); %get two points from the usersubplot(1,2,2); image(I2/2

7、55); axis image; hold on;title(second input image);X2 Y2=ginput(2); %get two points from the user%estimate parameter vector(t);Z=X2 Y2; Y2-X2 ; 1 1 0 0 ; 0 0 1 1 ;xp=X1; Y1;t=Zxp; %solve the linear system%a=t(1); %=s cos(alpha)b=t(2); %=s sin(alpha)tx=t(3);ty=t(4);%construct transformation matrix(T)

8、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*1 1 w2 w2; 1 h2 1 h2; 1 1 1 1;Xpr=min(cp(1,:),0):max(cp(1,:),w1);% min x: max xYpr=min(cp(2,:),0):max(cp(2,:),h1); %min y :max yXp,Yp=ndgrid(Xpr, Ypr);wp hp=size(Xp); %=size(Yp) % do backwards tr

9、ansform(from out to in)X=TXp(:) Yp(:) ones(wp*hp, 1); %warp%re-sample pixel values with bilinear interpolationclear Ip;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%offset and copy original image into the warped imageoffset= -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,:);%show the resultfigure; image(Ip/255); axis image;title(mosaic image);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 网络科技 > 计算机原理

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报