matlab程序修改:显示X2没有定义,如何修改?
问题补充:function [IP]= masaic(image1,image2,X1,X2,Y1,Y2,num)
image1=imread('C:UserswenjingDesktop课设图片left.jpg');%读入left图像给image1
image2=imread('C:UserswenjingDesktop课设图片right.jpg');%读入right图像给image2
I1=double(image1);
[h1 w1 d1]=size(I1);
I2=double(image2);
[h2 w2 d2]=size(I2);
% 估计参数向量(t)
Z = [ X2' Y2' ; Y2' -X2' ; 1 1 0 0 ; 0 0 1 1 ]';
xp = [ X1 ; Y1 ];
t = Z xp; %
a = t(1); % = s cos(alpha)
b = t(2); % = s sin(alpha)
tx = t(3);
ty = t(4);
% 构建变换矩阵(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;
显示X2没有定义,应该怎么修改?
提问者:网路小时工 2回答 浏览次数:1895 提问时间:
2021/12/01 11:48