% 1. 读取两帧图像
image1 = imread('1.png');
image2 = imread('2.png');
%
% 2. 使用SURF检测特征点
points1 = detectSURFFeatures(image1);
points2 = detectSURFFeatures(image2);
%
% 3. 提取特征描述符
[features1, points1] = extractFeatures(image1, points1);
[features2, points2] = extractFeatures(image2, points2);
%
% 4. 匹配特征点
indexPairs = matchFeatures(features1, features2);
%
% 5. 获取匹配点的坐标
matchedPoints1 = points1(indexPairs(:, 1), :).Location;
matchedPoints2 = points2(indexPairs(:, 2), :).Location;
%
% 检查匹配点数量
if size(matchedPoints1, 1) < 3
error('匹配点数量不足,无法估计几何变换。');
end
%
% 6. 使用RANSAC算法估计变换矩阵
[tform, inliers] = estimateGeometricTransform(matchedPoints1, matchedPoints2, 'affine');
%
% 7. 进行配准叠加
outputView = imref2d(size(image1));
registeredImage = imwarp(image2, tform, 'OutputView', outputView);
%
% 8. 在叠加图像中显示配准结果
figure;
imshowpair(image1, registeredImage, 'montage');
title('Overlay of Frame 1 and Registered Frame 2');
%
% 9. 保存结果
imwrite(registeredImage, 'registered_frame2.jpg');
Matlab实现基础的SUFT特征角点匹配与配准叠加
于 2023-11-16 19:59:48 首次发布