forked from ibrahim-radwan/ImageAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatching_harris.m
41 lines (31 loc) · 1.2 KB
/
matching_harris.m
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
close all;
clear;
clc;
im_path = 'images/robocup_image1.jpeg';
im = imread(im_path);
im_gray = rgb2gray(im);
x_start = 418;
y_start = 155;
x_end = 466;
y_end = 225;
template = im(y_start:y_end, x_start:x_end, :);
template_gray = rgb2gray(template);
figure; imshow(template_gray);
im_gray = rgb2gray(imread('images/robocup_image2.jpeg'));
% template matching based on Sum of Absolute Differences (SAD)
[height_t, width_t, ~] = size(template);
[height, width, ~] = size(im);
% Detect the salient points using Harris technique
pointsImg = detectHarrisFeatures(im_gray);
pointsTemplate = detectHarrisFeatures(template_gray);
% Feature description
[featuresImg, validPointsImg] = extractFeatures(im_gray, pointsImg); % original image
[featuresTemplate, validPointsTemplate] = extractFeatures(template_gray, pointsTemplate); % template image
% Match the features
indexPairs = matchFeatures(featuresImg, featuresTemplate);
% Location of the matched points
matchedPointsImg = validPointsImg(indexPairs(:, 1), :);
matchedPointsTemplate = validPointsTemplate(indexPairs(:, 2), :);
% time to show
figure;
showMatchedFeatures(im_gray, template_gray, matchedPointsImg, matchedPointsTemplate);