修正图像拼接中的图像尺寸

Correct image size in image mosaic

我正在使用 SURF.the 在 Matlab 中实现图像拼接,问题是

outputView = imref2d(size(img1)*2);
Ir = imwarp(img2,tform,'OutputView',outputView); 

它产生

我想要这样的东西

如果我改变

outputView = imref2d(size(img1)*2);

outputView = imref2d(size(img1));

matlab 裁剪第二张图片,使其在转换后适合第一张图片的大小。

请注意,当您相对于目标平面扭曲图像时,这个新平面中的许多像素都等于 0。一个非常基本的算法是简单地对图像设置阈值,以便找到大于 0 的值,然后找到包含非零像素的最大边界框...然后裁剪:

[rows,cols] = find(Ir(:,:,1) > 0);
topLeftRow = min(rows);
topLeftCol = min(cols);
bottomRightRow = max(rows);
bottomRightCol = max(cols);

Ir_crop = Ir(topLeftRow:bottomRightRow, topLeftCol:bottomRightCol, :);