- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
拼接图像matlab可执行的程序
图1 待拼接图像
图2 拼接后的图像
Matlab程序代码:
I1 = double(imread(left.bmp));
[h1 w1 d1] = size(I1);
I2 = double(imread(right.bmp));
[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 usersubplot(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 = Z \ xp; % 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)
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 x
Ypr = min( [ cp(2,:) 0 ] ) : max( [cp(2,:) h1] ); % 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,1) ]; % warp
% re-sample pixel values with bilinear interpolation
clear Ip;
xI = reshape( X(1,:),wp,hp);
yI = reshape( X(2,:),wp,hp);
Ip(:,:,1) = interp2(I2(:,:,1), xI, yI, *bilinear); % red
Ip(:,:,2) = interp2(I2(:,:,2), xI, yI, *bilinear); % green
Ip(:,:,3) = interp2(I2(:,:,3), xI, yI, *bilinear); % blue
% offset and copy original image into the warped image
offset = -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 result
figure; image(Ip/255); axis image;
title(mosaic image);
I1 = double(imread(left.bmp));
[h1 w1 d1] = size(I1);
I2 = double(imread(right.bmp));
[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 tw
文档评论(0)