Advertisement

surf matlab 图像拼接,【Matlab】基于特征点的全景图像拼接

阅读量:

该文本描述了基于特征检测和匹配的图像拼接方法,用于创建全景图。主要步骤包括:加载图像、图像配准(使用SURF算法检测特征点并估算几何变换)、初始化全景图(通过计算输出空间限制确定全景图尺寸)以及创建全景图(使用imwarp和AlphaBlender将图像映射到全景图中)。该方法在机器视觉应用中具有重要意义,例如图像配准、跟踪和目标检测。相关论文提到自动 panoramic图像拼接方法,使用不变特征实现图像对齐。

该链接展示了基于特征的全景图像拼接的Matlab计算机视觉示例。

概述

步骤一 加载图片

步骤二 图像配准

步骤三 初始化全景图

步骤四 创建全景图

总结

相关论文

概述

在机器视觉领域,特征提取与匹配被视为一种关键算法(如图1所示),其应用广泛,涵盖图像配准、目标检测与跟踪等场景。以本例而言,我们通过基于特征的方法实现了图像拼接。在处理流程中,首先采用图像配准特征点。与仅依赖单幅图像配准不同,本例采用了多组图像间的配准方式完成拼接任务。

步骤一 加载图片

% 以图像集的方法加载图片

buildingDir = fullfile(toolboxdir('vision'), 'visiondata', 'building');

buildingScene = imageSet(buildingDir);

% 显示要拼接的所有图片

montage(buildingScene.ImageLocation)

步骤二 图像配准

使用下面的步骤来进行图像对配准操作。

在I(n)和I(n-1)之间检测和匹配特征点

估算从I(n)映射到I(n-1)上的几何变换T(n)

计算I(n)在全景图里的变换T(1)*…*T(n-1)*T(n).

% 从图片集中读取第一幅图像

I = read(buildingScene, 1);

% 将图像转为灰度图,再提取I(1)的特征点,用的是surf算法。

grayImage = rgb2gray(I);

points = detectSURFFeatures(grayImage);

[features, points] = extractFeatures(grayImage, points);

% 初始化所有变换的恒等矩阵。

tforms(buildingScene.Count) = projective2d(eye(3));

% Iterate over remaining image pairs

for n = 2:buildingScene.Count

% Store points and features for I(n-1).

% 存储前一图像的特征点坐标和值。

pointsPrevious = points;

featuresPrevious = features;

% Read I(n).

% 读取第n张图片。

I = read(buildingScene, n);

% Detect and extract SURF features for I(n).

%检测和提取surf特征值。

grayImage = rgb2gray(I);

points = detectSURFFeatures(grayImage);

[features, points] = extractFeatures(grayImage, points);

% 匹配I(n)和I(n-1)之间对应的特征点

indexPairs = matchFeatures(features, featuresPrevious, ‘Unique’, true);

matchedPoints = points(indexPairs(:,1), :);

matchedPointsPrev = pointsPrevious(indexPairs(:,2), :);

% 用MSAC算法计算几何变化。

TFORMS(n) 是通过调用 computeGeometricTransformation 函数计算得到的,其参数包括 point sets 和 previous point sets。

‘projective’, ‘Confidence’, 99.9, ‘MaxNumTrials’, 2000);

% 计算T(1) * … * T(n-1) * T(n)

tforms(n).T = tforms(n-1).T * tforms(n).T;

end

在本研究中,所有tforms的变换操作都是基于第一幅图像进行的。为了简化图像配准处理代码的编写过程,我们可以通过对所有图像进行批量处理来实现这一目标。然而,以第一张图像作为配准的初始基准图,无法获得最佳的配准效果,原因在于该基准图包含了所有后续图像的畸变信息。因此,建议采用中间场景作为配准的基准图,这样可以显著减少配准过程中的畸变程度。

通过projective2d的outputLimits策略确定每个变换输出的极限值,这些极限值则用于自动确定中间场景图像的轮廓。

imageSize = size(I); % 所有的图像尺寸都是一样的

% 对每个投影变化找到输出的空间坐标限制值。

for i = 1:numel(tforms)

[xlim(i,:), ylim(i,:)] = outputLimits(tforms(i), [1 imageSize(2)], [1 imageSize(1)]);

end

随后,我们通过计算每个变换X方向上的极限的平均值,确定出中间的图像。主要采用X方向上的极限是因为场景主要在水平方向上。此外,如果存在其他图像,应当同时考虑XY方向上的极限以确保准确查找中心图像。

avgXLim = mean(xlim, 2);

[~, idx] = sort(avgXLim);

centerIdx = floor((numel(tforms)+1)/2);

centerImageIdx = idx(centerIdx);

最后,将中心图像的反变换应用到所有的图像变换中。

Tinv = invert(tforms(centerImageIdx));

for i = 1:numel(tforms)

tforms(i).T = Tinv.T * tforms(i).T;

end

步骤三 初始化全景图

接下来,创建一个空的全景图用来存放所有图像。

通过outputLimits方法计算最小和最大输出限制值,这些数值用于确定全景图的尺寸。

for i = 1:numel(tforms)

[xlim(i,:), ylim(i,:)] = outputLimits(tforms(i), [1 imageSize(2)], [1 imageSize(1)]);

end

% 找到输出空间限制的最大最小值

xMin = min([1; xlim(:)]);

xMax = max([imageSize(2); xlim(:)]);

yMin = min([1; ylim(:)]);

yMax = max([imageSize(1); ylim(:)]);

% 全景图的宽高

width = round(xMax - xMin);

height = round(yMax - yMin);

% 生成空数据的全景图

panorama = zeros([height width 3], 'like', I);

步骤四 创建全景图

通过imwarp将图像映射至全景图中,继而使用vision.AlphaBlender将图像进行重叠处理。

blender = vision.AlphaBlender('Operation', 'Binary mask', ...

'MaskSource', 'Input port');

% Create a 2-D spatial reference object defining the size of the panorama.

xLimits = [xMin xMax];

yLimits = [yMin yMax];

panoramaView = imref2d([height width], xLimits, yLimits);

% Create the panorama.

for i = 1:buildingScene.Count

I = read(buildingScene, i);

% Transform I into the panorama.

warpedImage = imwarp(I, tforms(i), 'OutputView', panoramaView);

% Overlay the warpedImage onto the panorama.

panorama = step(blender, panorama, warpedImage, warpedImage(:,:,1));

end

figure

imshow(panorama)

总结

该方法在示例中演示了图像配准技术以生成全景图。附录中提供了图像融合与对齐的全景图拼接改进方案。

相关论文

[1] Matthew Brown and David G. Lowe. 2007. Automatic Stitching of Panoramic Images based on Invariant Features. International Journal of Computer Vision 74, 1 (August 2007), 59-73.

全部评论 (0)

还没有任何评论哟~