基于 SIFT 对图像进行局部特征匹配(Matlab代码实现)

简介: 基于 SIFT 对图像进行局部特征匹配(Matlab代码实现)

💥1 概述

为了提高特征点匹配的准确率,提出了一种基于改进混合滤波、特征描述符降维、SIFT特征匹配、RANSAC剔除误匹配点以及PSO算法的特征点匹配。首先将场景图像进行滤波处理达到去噪效果,然后通过特征描述符降维以减少计算量,再通过RANSAC对基于SIFT的特征点匹配进行误匹配的剔除,最后使用PSO算法进行优化以寻找到最佳的Ratio值。通过在模糊、较暗、较亮和遮挡4种以机械手为背景的场景下的图像,进行4种算法的对比实验,最后表明SIFT特征匹配算法的误匹配率最小,精确度最高。在本文章中,我们实现了哈里斯角检测器来获取与角像素相对应的兴趣点。设计用于检测图像多个比例的角落。实现了 SIFT 算法,用于获取之前找到的角点的局部特征描述符。每个角点都使用其周围图像块的梯度直方图(HoG)进行描述。使用最近距离匹配实现特征匹配,并使用 k-d 树实现 KNN 搜索。


📚2 运行结果

部分代码:

% Local Feature Stencil Code
% CS 4476 / 6476: Computer Vision, Georgia Tech
% Written by James Hays
% This script 
% (1) Loads and resizes images
% (2) Finds interest points in those images                 (you code this)
% (3) Describes each interest point with a local feature    (you code this)
% (4) Finds matching features                               (you code this)
% (5) Visualizes the matches
% (6) Evaluates the matches based on ground truth correspondences
tic
close all
%% 1) Load stuff
% There are numerous other image sets in the supplementary data on the
% project web page. You can simply download images off the Internet, as
% well. However, the evaluation function at the bottom of this script will
% only work for three particular image pairs (unless you add ground truth
% annotations for other image pairs). It is suggested that you only work
% with the two Notre Dame images until you are satisfied with your
% implementation and ready to test on additional images. A single scale
% pipeline works fine for these two images (and will give you full credit
% for this project), but you will need local features at multiple scales to
% handle harder cases.
  image1 = imread('../data/Notre Dame/921919841_a30df938f2_o.jpg');
  image2 = imread('../data/Notre Dame/4191453057_c86028ce1f_o.jpg');
  eval_file = '../data/Notre Dame/921919841_a30df938f2_o_to_4191453057_c86028ce1f_o.mat';
 %image1 = imread('../data/agra_fort.jpg');
 %image2 = imresize(image1,0.5);
% %This pair is relatively easy (still harder than Notre Dame, though)
% image1 = imread('../data/Mount Rushmore/9021235130_7c2acd9554_o.jpg');
% image2 = imread('../data/Mount Rushmore/9318872612_a255c874fb_o.jpg');
% eval_file = '../data/Mount Rushmore/9021235130_7c2acd9554_o_to_9318872612_a255c874fb_o.mat';
%This pair is relatively difficult
% image1 = imread('../data/Episcopal Gaudi/4386465943_8cf9776378_o.jpg');
% image2 = imread('../data/Episcopal Gaudi/3743214471_1b5bbfda98_o.jpg');
% eval_file = '../data/Episcopal Gaudi/4386465943_8cf9776378_o_to_3743214471_1b5bbfda98_o.mat';
image1 = single(image1)/255;
image2 = single(image2)/255;
%make images smaller to speed up the algorithm. This parameter gets passed
%into the evaluation code so don't resize the images except by changing
%this parameter.
scale_factor = 0.5; 
image1 = imresize(image1, scale_factor, 'bilinear');
image2 = imresize(image2, scale_factor, 'bilinear');
% You don't have to work with grayscale images. Matching with color
% information might be helpful.
image1_bw = rgb2gray(image1);
image2_bw = rgb2gray(image2);
feature_width = 16; %width and height of each local feature, in pixels. 
toc 
%% 2) Find distinctive points in each image. Szeliski 4.1.1
% !!! You will need to implement get_interest_points. !!!
% Harris Corner Detection
% [x1, y1] = get_interest_points(image1_bw, feature_width, 1);
% [x2, y2] = get_interest_points(image2_bw, feature_width, 1);
% % Adaptive non-maximal detection
% [x1, y1] = get_interest_points_anms(image1_bw, feature_width);
% toc
% [x2, y2] = get_interest_points_anms(image2_bw, feature_width);
% % Scaling with harris corner detection
[x1, y1, confidence1, scale1] = get_interest_points_scaling(image1_bw, feature_width);
[x2, y2, confidence2, scale2] = get_interest_points_scaling(image2_bw, feature_width);
toc
%show_correspondence(image1, image2, x1, y1, x2, y2);
% % Use cheat_interest_points only for development and debugging!
% [x1, y1, x2, y2] = cheat_interest_points(eval_file, scale_factor);
%show_correspondence(image1, image2, x1, y1, x2, y2);
%% 3) Create feature vectors at each interest point. Szeliski 4.1.2
% !!! You will need to implement get_features. !!!
% SIFT
% [image1_features] = get_features(image1_bw, x1, y1, feature_width);
% [image2_features] = get_features(image2_bw, x2, y2, feature_width);
% SIFT with scaling
[image1_features] = get_features_scaling(image1_bw, x1, y1, feature_width, scale1);
[image2_features] = get_features_scaling(image2_bw, x2, y2, feature_width, scale2);
toc
%% 4) Match features. Szeliski 4.1.3
% !!! You will need to implement get_features. !!!
% % Exhaustive search
 [matches, confidences] = match_features(image1_features, image2_features);
% % Knnsearch with kdTree
%[matches, confidences] = match_features_knnsearch(image1_features, image2_features);
%matches = matchFeatures(feat1, feat2);
toc
%% 5) Visualization
% You might want to set 'num_pts_to_visualize' and 'num_pts_to_evaluate' to
% some constant (e.g. 100) once you start detecting hundreds of interest
% points, otherwise things might get too cluttered. You could also
% threshold based on confidence.
% There are two visualization functions. You can comment out one of both of
% them if you prefer.
num_pts_to_visualize = size(matches,1);
show_correspondence(image1, image2, x1(matches(1:num_pts_to_visualize,1)), ...
                                    y1(matches(1:num_pts_to_visualize,1)), ...
                                    x2(matches(1:num_pts_to_visualize,2)), ...
                                    y2(matches(1:num_pts_to_visualize,2)));
show_correspondence2(image1, image2, x1(matches(1:num_pts_to_visualize,1)), ...
                                     y1(matches(1:num_pts_to_visualize,1)), ...
                                     x2(matches(1:num_pts_to_visualize,2)), ...
                                     y2(matches(1:num_pts_to_visualize,2)));
%% 6) Evaluation
% This evaluation function will only work for the Notre Dame, Episcopal
% Gaudi, and Mount Rushmore image pairs. Comment out this function if you
% are not testing on those image pairs. Only those pairs have ground truth
% available. You can use collect_ground_truth_corr.m to build the ground
% truth for other image pairs if you want, but it's very tedious. It would
% be a great service to the class for future years, though!
num_pts_to_evaluate = size(matches,1);
good_matches = evaluate_correspondence(image1, image2, eval_file, scale_factor, ... 
                        x1(matches(1:num_pts_to_evaluate,1)), ...
                        y1(matches(1:num_pts_to_evaluate,1)), ...
                        x2(matches(1:num_pts_to_evaluate,2)), ...
                        y2(matches(1:num_pts_to_evaluate,2)));


🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]林曦蕾.图像局部特征匹配算法发展综述[J].现代计算机(专业版),2019(09):89-93.

[2]徐澳,华云松,夏春蕾.,陈诗雨.一种基于SIFT的改进特征点匹配算法[J].软件,2022,43(09):83-86+119.

🌈4 Matlab代码实现

相关文章
|
3月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
196 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
3月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
128 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
|
3月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
88 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
6月前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
6月前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
6月前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
|
6月前
|
Serverless
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
|
6月前
|
供应链 算法
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
|
6月前
|
算法 调度
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)