ORB特征提取和匹配

*
一、步骤
二、代码
三、部分结果展示

+
*
3.1 使用Sobel算子且方向为vertical,进行边缘检测
3.2 特征点提取(部分)
3.3 特征点匹配

一、步骤

Step1:读取彩色图片
1.新建实验用的文件夹,准备好实验用到的图片,在MATLAB2021a软件中编写相关脚本文件。
2.清理变量空间以及命令行。
3.用imread()函数读取彩色图片,使用imfuse()函数进行简单的图像复合用imshow()函数显示出来即可看到2张图的差异;将上诉3幅图用subplot()展示在一张figure中。
Step2:彩色图像转化为灰度图
1.直接使用rgb2gray()函数将上述2幅rgb图像转化为灰度图。
2.做与Step1一样的展示,这里使用imshowpair()函数来展示两种灰度图的差异。
3.使用edge()函数同时选用canny参数对灰度图进行canny算子边缘检测,修改sigma值。
4.采用与2相同的方式对结果进行展示。
Step3 对左右图像分别进行特征点提取:
1.使用detectORBFeatures()函数对灰度图进行特征点提取。
2.观察特征点变量发现两张图都提取出了9000余个特征点,不便直接展示出来。
3.分别展示出两幅灰度图的原图像,并在其基础上使用selectStrongest()函数分别展示其最大的3000个特征点。
Step 4:根据特征点生成图像的特征向量
使用extractFeatures()函数生成图像的特征向量。
Step 5:对左右图像提取的特征点进行匹配
1.使用matchFeatures()函数进行两张图的特征点匹配,返回68562的向量,即互相匹配的6856对点所对应的坐标索引。
2.使用showMatchedFeatures()函数显示结果,分别选用默认参数falsecolor和montage,
第一种参数将第一幅图显示为red,第二张图显示为cyan,放在一张图里面;而第二种参数则将两幅图并排显示。
Step 6: 预测几何变化,去除不满足变化的野值*
1.使用estimateGeometricTransform()函数预测几何变化,选用不同参数,去除不满足变化的野值。
2.采用Step5中相似的方式显示结果 。

二、代码

clc
clear
close all

%%  Step1:读取彩色图片
img_left_color  = imread('orange1.PNG');
img_right_color = imread('orange2.PNG');

% 显示结果
figure('Name','Step1:读取彩色图片')
subplot('Position',[0.0 0.0 0.66 1])
imshow([img_left_color img_right_color])
title("左图和右图")
subplot('Position',[0.67 0.0 0.33 1])
imshow(imfuse(img_left_color, img_right_color))
title("左右图像差异")

%% Step2:彩色图像转化为灰度图
img_left_gray  = rgb2gray(img_left_color);
img_right_gray = rgb2gray(img_right_color);

% 显示结果
figure('Name','Step2:彩色图像转化为灰度图')
subplot('Position',[0.0 0.0 0.66 1])
imshow([img_left_gray img_right_gray])
title("左图和右图")
subplot('Position',[0.67 0.0 0.33 1])
imshowpair(img_left_gray,img_right_gray) %等效于 imshow(imfuse(img_left_gray, img_right_gray))
title("左右图像差异")

%% Step2.1:对灰度图进行边缘检测
img_left_edge  = edge(img_left_gray,'canny',[],1);      % 使用canny算子进行边缘检测
img_right_edge = edge(img_right_gray,'canny',[],1);     % 使用canny算子进行边缘检测

% 显示结果
figure('Name','Step2.1:对灰度图进行边缘检测')
subplot('Position',[0.0 0.0 0.66 1])
imshow([img_left_edge img_right_edge])
title("左图和右图")
subplot('Position',[0.67 0.0 0.33 1])
imshowpair(img_left_edge,img_right_edge)
title("左右图像差异")

%% Step3:对左右图像分别进行特征点提取
left_ORB_points  = detectORBFeatures(img_left_gray);
right_ORB_points = detectORBFeatures(img_right_gray);

% 显示结果
figure('Name','Step3:对左右图像分别进行特征点提取')
subplot('Position',[0.0 0.0 0.5 4])
imshow(img_left_gray);hold on;
title("部分左图特征点")
plot(left_ORB_points(1:2:9825,:),'showOrientation',true);
subplot('Position',[0.5 0.0 0.5 4])
imshow(img_right_gray);hold on;
title("部分右图特征点")
plot(right_ORB_points(1:2:9994,:),'showOrientation',true);

%% Step4:根据特征点生成图像的特征向量
[left_features,  left_ORB_points]  = extractFeatures(img_left_gray,  left_ORB_points);
[right_features, right_ORB_points] = extractFeatures(img_right_gray, right_ORB_points);

%% Step5: 对左右图像提取的特征点进行匹配
image_pairs = matchFeatures(left_features, right_features,'MatchThreshold',15); % 调整匹配阈值观察变化
left_matched_points  = left_ORB_points(image_pairs(:, 1), :);
right_matched_points = right_ORB_points(image_pairs(:, 2), :);

% 显示结果
figure('Name','Step5:对左右图像提取的特征点进行匹配')
subplot('Position',[0.0 0.0 0.66 1])
showMatchedFeatures(img_left_gray, img_right_gray, left_matched_points,right_matched_points, 'montage');
title("特征点匹配结果")
subplot('Position',[0.67 0.0 0.33 1])
showMatchedFeatures(img_left_gray, img_right_gray, left_matched_points,right_matched_points);
title("特征点匹配结果")

%% Step6: 预测几何变化,去除不满足变化的野值(三种几何变换变化的方法:% 'similarity'(相似) | 'affine'(仿射) | 'projective'(投影))
[tform, left_matched_points_estimate, right_matched_points_estimate] = estimateGeometricTransform(left_matched_points, right_matched_points, 'projective');
% 显示结果
figure('Name','Step6: 预测几何变化,去除不满足变化的野值')
subplot('Position',[0.0 0.0 0.66 1])
showMatchedFeatures(img_left_gray, img_right_gray, left_matched_points_estimate,right_matched_points_estimate, 'montage');
title("去除不满足几何变化的特征点的匹配结果")
subplot('Position',[0.67 0.0 0.33 1])
showMatchedFeatures(img_left_gray, img_right_gray, left_matched_points_estimate,right_matched_points_estimate);
title("去除不满足几何变化的特征点的匹配结果")

三、部分结果展示

3.1 使用Sobel算子且方向为vertical,进行边缘检测

ORB特征提取和匹配
; 3.2 特征点提取(部分)

ORB特征提取和匹配
3.3 特征点匹配

ORB特征提取和匹配

Original: https://blog.csdn.net/weixin_43764974/article/details/121743141
Author: 感谢地心引力
Title: ORB特征提取和匹配

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/641712/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球