forked from LucyKuncheva/Video-Processing-Library-MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfox_match_two_frames_surf.m
More file actions
62 lines (52 loc) · 2.18 KB
/
Copy pathfox_match_two_frames_surf.m
File metadata and controls
62 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [match, value] = fox_match_two_frames_surf(A,B,threshold,vis)
%=======================================================================
%fox_match_two_frames_surf Calculate the match between two images using
%SURF features.
% [match, value] = fox_match_two_frames_surf(A,B,threshold,vis) uses
% SURF features to calcuate the match between two images
%
% Input -----
% 'A': image 1
% 'B': image 2
% 'threshold': thresholf for the match; match is declared if
% distance is <= threshold
% 'vis': 0/1 visualisation flag
%
% Output -----
% 'match': match output - 0 no match, 1 match (logical variable)
% 'value': distance value
%========================================================================
% (c) Fox's Vis Toolbox ^--^
% 08.06.2018 ----------------------------------------------------- \oo/
% -------------------------------------------------------------------\/-%
if nargin == 3, vis = 0; end
if ndims(A) == 3; A = rgb2gray(A); B = rgb2gray(B); end
s1 = detectSURFFeatures(A);
s2 = detectSURFFeatures(B);
[Features1, Points1] = extractFeatures(A, s1);
[Features2, Points2] = extractFeatures(B, s2);
Pairs = matchFeatures(Features1, Features2, 'Metric','SSD',...
'MaxRatio',0.5,'MatchThreshold',5);
PairsReverse = matchFeatures(Features2, Features1,...
'Metric','SSD','MaxRatio',0.5,'MatchThreshold',5);
p1 = size(Points1,1); p2 = size(Points2,1);
m = min(size(Pairs,1),size(PairsReverse,1)); % number of matched points
if vis % show the pictures
matchedPoints1 = Points1(Pairs(:, 1), :);
matchedPoints2 = Points2(Pairs(:, 2), :);
matchedPointsR2 = Points1(PairsReverse(:, 2), :);
matchedPointsR1 = Points2(PairsReverse(:, 1), :);
figure
subplot(2,1,1)
showMatchedFeatures(A, B, matchedPoints1, matchedPoints2,...
'montage');
subplot(2,1,2)
showMatchedFeatures(B, A, matchedPointsR2, matchedPointsR1,...
'montage');
end
if ~isempty(p1) && ~isempty(p2) % there are salient points
value = 1 - 2*m/(p1+p2); % mini F-measure
else
value = inf;
end
match = value < threshold;