-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sandbox.m
138 lines (112 loc) · 3.54 KB
/
Sandbox.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
clc;
clear all;
close all;
%% Load and show the cookie data
okDataFile = dir('CookieData\ok\*.jpg');
nokDataFile = dir('CookieData\nok\*.jpg');
sample_OK1 = rgb2gray(imread([okDataFile(1).folder, '\', okDataFile(1).name]));
sample_OK1_c = imread([okDataFile(1).folder, '\', okDataFile(1).name]);
sample_OK2 = rgb2gray(imread([okDataFile(3).folder, '\', okDataFile(3).name]));
%sample_OK2 = imresize(imrotate(sample_OK1,-20),1.2);
sample_SH1 = rgb2gray(imread([nokDataFile(1).folder, '\', nokDataFile(1).name]));
sample_SH1_c = imread([nokDataFile(1).folder, '\', nokDataFile(1).name]);
sample_CD1 = rgb2gray(imread([nokDataFile(28).folder, '\', nokDataFile(28).name]));
sample_CD1_c = imread([nokDataFile(28).folder, '\', nokDataFile(28).name]);
sample_SO1 = rgb2gray(imread([nokDataFile(38).folder, '\', nokDataFile(38).name]));
sample_SO1_c = imread([nokDataFile(38).folder, '\', nokDataFile(38).name]);
%% Get the SIFT features
disp('.........................');
disp('SIFT Features: ');
tic
SIFTpoints_OK1 = detectSIFTFeatures(sample_OK1);
SIFTpoints_OK2 = detectSIFTFeatures(sample_OK2);
SIFTpoints_SH1 = detectSIFTFeatures(sample_SH1);
SIFTpoints_CD1 = detectSIFTFeatures(sample_CD1);
SIFTpoints_SO1 = detectSIFTFeatures(sample_SO1);
toc
figure(1)
hold on
title('SURF features')
subplot(2, 2, 1)
imshow(sample_OK1_c)
hold on
plot(SIFTpoints_OK1.selectStrongest(5))
subplot(2, 2, 2)
imshow(sample_SH1_c)
hold on
plot(SIFTpoints_SH1.selectStrongest(5))
subplot(2, 2, 3)
imshow(sample_CD1_c)
hold on
plot(SIFTpoints_CD1.selectStrongest(5))
subplot(2, 2, 4)
imshow(sample_SO1_c)
hold on
plot(SIFTpoints_SO1.selectStrongest(5))
%% Get the SURF features
disp('.........................');
disp('SURF Features: ');
tic
SURFpoints_OK1 = detectSURFFeatures(sample_OK1);
SURFpoints_SH1 = detectSURFFeatures(sample_SH1);
SURFpoints_CD1 = detectSURFFeatures(sample_CD1);
SURFpoints_SO1 = detectSURFFeatures(sample_SO1);
toc
figure(2)
subplot(2, 2, 1)
imshow(sample_OK1_c)
hold on
plot(SURFpoints_OK1.selectStrongest(5))
subplot(2, 2, 2)
imshow(sample_SH1_c)
hold on
plot(SURFpoints_SH1.selectStrongest(5))
subplot(2, 2, 3)
imshow(sample_CD1_c)
hold on
plot(SURFpoints_CD1.selectStrongest(5))
subplot(2, 2, 4)
imshow(sample_SO1_c)
hold on
plot(SURFpoints_SO1.selectStrongest(5))
%% Get the Harris features
disp('.........................');
disp('Harris Features: ');
tic
HARRpoints_OK1 = detectHarrisFeatures(sample_OK1);
HARRpoints_SH1 = detectHarrisFeatures(sample_SH1);
HARRpoints_CD1 = detectHarrisFeatures(sample_CD1);
HARRpoints_SO1 = detectHarrisFeatures(sample_SO1);
toc
figure(3)
subplot(2, 2, 1)
imshow(sample_OK1)
hold on
plot(HARRpoints_OK1.selectStrongest(10))
subplot(2, 2, 2)
imshow(sample_SH1)
hold on
plot(HARRpoints_SH1.selectStrongest(10))
subplot(2, 2, 3)
imshow(sample_CD1)
hold on
plot(HARRpoints_CD1.selectStrongest(10))
subplot(2, 2, 4)
imshow(sample_SO1)
hold on
plot(HARRpoints_SO1.selectStrongest(10))
%% Match features
I1 = sample_OK1;
I2 = sample_OK2;
points1 = SIFTpoints_OK1;
points2 = SIFTpoints_OK2;
[features1,valid_points1] = extractFeatures(I1, points1);
[features2,valid_points2] = extractFeatures(I2, points2);
% Match the features
indexPairs = matchFeatures(features1,features2);
% Retrieve the locations of the corresponding points for each image
matchedPoints1 = valid_points1(indexPairs(:,1),:);
matchedPoints2 = valid_points2(indexPairs(:,2),:);
% Visualize the corresponding points. You can see the effect of translation between the two images despite several erroneous matches.
figure(4);
showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);