-
Notifications
You must be signed in to change notification settings - Fork 2
/
feature_main.c
284 lines (229 loc) · 4.12 KB
/
feature_main.c
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include "header.h"
#include "proto.h"
int feature_main(
char *filename_image,
double sigma,
feat_struct **pfeat_arr,
int *pfeat_nbr
)
{
char *ext;
double ***gauss_pyr_image;
int *gauss_pyr_width;
int *gauss_pyr_height;
int width;
int height;
int *image_rgb;
int image_doubling_flag;
int init_width;
int init_height;
double *init_image;
double val_dbl;
int octave_nbr;
int interval_nbr;
double ***dog_pyr_image;
feat_struct *feat_arr;
int feat_nbr;
int val_int;
double octave_nbr_dbl;
int octave;
int interval;
int img_border;
int min_size_int;
double min_size_dbl;
int err_flag;
/*
Load image
*/
err_flag= load_rgb_image(
filename_image,
&image_rgb,
&width,
&height
);
if ( err_flag == 1 ) {
fprintf(stdout,"Filename extension for %s not recognized!\n",
filename_image);
fprintf(stdout,"Supported: tiff, TIFF, tif, TIF, png, PNG, jpeg, JPEG, jpg, JPG\n");
return 1;
}
/*
Set the image doubling flag
0 means no doubling
1 means doubling (expect more features)
*/
image_doubling_flag= 0;
/*
Create init image
(values between 0.0 and 1.0)
*/
feature_create_init_image(
width,
height,
image_rgb,
sigma,
image_doubling_flag,
&init_width,
&init_height,
&init_image
);
/*
Compute the number of octaves
*/
/*
Set the image border in which the feaures are ignored
*/
img_border= 5;
/*
Compute minimum image size
*/
min_size_int= 2*img_border+2;
min_size_dbl= (double)min_size_int;
val_int= init_height;
if ( init_width < val_int )
val_int= init_width;
val_dbl= (double)val_int;
octave_nbr_dbl= (log(val_dbl)-log(min_size_dbl))/log(2);
octave_nbr= (int)octave_nbr_dbl;
/*
Let's cap the number of octaves (as in Monasse)
*/
/*
if ( octave_nbr > 4 )
octave_nbr= 4;
*/
/*
fprintf(stdout," Number of octaves = %d\n",octave_nbr);
*/
/*
Set the interval nbr
(nbr of scales)
*/
interval_nbr= 3;
/*
Build scale space
*/
feature_build_scale_space(
init_width,
init_height,
init_image,
octave_nbr,
interval_nbr,
sigma,
&gauss_pyr_image,
&gauss_pyr_width,
&gauss_pyr_height
);
/*
Build the Difference of Gaussians (DoG) space
*/
feature_build_dog_space(
octave_nbr,
interval_nbr,
gauss_pyr_image,
gauss_pyr_width,
gauss_pyr_height,
&dog_pyr_image
);
/*
Get the features
*/
feature_detect_features(
octave_nbr,
interval_nbr,
gauss_pyr_image,
gauss_pyr_width,
gauss_pyr_height,
dog_pyr_image,
&feat_arr,
&feat_nbr
);
/*
Get the scale (sigma) for each feature
*/
feature_compute_features_sigma(
interval_nbr,
sigma,
feat_arr,
feat_nbr
);
if ( image_doubling_flag == 1 ) {
/*
Adjust the features to account for initial image doubling
*/
feature_adjust_features_image_doubling(
interval_nbr,
sigma,
feat_arr,
feat_nbr
);
}
/*
Compute orientation histogram for each feature and
potentially add features if peak high enough
*/
feature_compute_features_orientation_histogram(
octave_nbr,
interval_nbr,
gauss_pyr_image,
gauss_pyr_width,
gauss_pyr_height,
dog_pyr_image,
&feat_arr,
&feat_nbr
);
/*
Compute the descriptors for each feature
*/
feature_compute_descriptors(
octave_nbr,
interval_nbr,
gauss_pyr_image,
gauss_pyr_width,
gauss_pyr_height,
dog_pyr_image,
feat_arr,
feat_nbr
);
/*
Free gauss_pyr_image
*/
for ( octave= 0 ; octave< octave_nbr ; octave++ ) {
for ( interval= 0 ; interval< interval_nbr+3 ; interval++ ) {
free(gauss_pyr_image[octave][interval]);
}
free(gauss_pyr_image[octave]);
}
free(gauss_pyr_image);
/*
Free gauss_pyr_width
*/
if ( octave_nbr > 0 )
free(gauss_pyr_width);
/*
Free gauss_pyr_height
*/
if ( octave_nbr > 0 )
free(gauss_pyr_height);
/*
Free dog_pyr_image
*/
for ( octave= 0 ; octave< octave_nbr ; octave++ ) {
for ( interval= 0 ; interval< interval_nbr+2 ; interval++ ) {
free(dog_pyr_image[octave][interval]);
}
free(dog_pyr_image[octave]);
}
free(dog_pyr_image);
/*
Free image_rgb
*/
free(image_rgb);
/*
Free init_image
*/
free(init_image);
(*pfeat_arr)= feat_arr;
(*pfeat_nbr)= feat_nbr;
return 0;
}