MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
sift.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann, Ronny Klowsky
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 *
9 * Notes:
10 * - The implementation allows a minmum octave of -1 only.
11 * - The descriptor extration supports 128 dimensions only.
12 * - Coordinates in the keypoint are relative to the octave.
13 * Absolute coordinates are obtained by (TODO why? explain):
14 * (x + 0.5, y + 0.5) * 2^octave - (0.5, 0.5).
15 * - Memory consumption is quite high, especially with large images.
16 * TODO: Find a more efficent code path to create octaves.
17 */
18#ifndef SFM_SIFT_HEADER
19#define SFM_SIFT_HEADER
20
21#include <string>
22#include <vector>
23
24#include "math/vector.h"
25#include "mve/image.h"
26#include "sfm/defines.h"
27
29
42class Sift
43{
44public:
48 struct Options
49 {
50 Options (void);
51
57
65
71
78
85
93
99
104
109 };
110
120 struct Keypoint
121 {
125 float sample;
127 float x;
129 float y;
130 };
131
138 {
140 float x;
142 float y;
144 float scale;
149 };
150
151public:
152 typedef std::vector<Keypoint> Keypoints;
153 typedef std::vector<Descriptor> Descriptors;
154
155public:
156 explicit Sift (Options const& options);
157
159 void set_image (mve::ByteImage::ConstPtr img);
161 void set_float_image (mve::FloatImage::ConstPtr img);
162
164 void process (void);
165
167 Keypoints const& get_keypoints (void) const;
168
170 Descriptors const& get_descriptors (void) const;
171
176 static void load_lowe_descriptors (std::string const& filename,
177 Descriptors* result);
178
179protected:
183 struct Octave
184 {
185 typedef std::vector<mve::FloatImage::Ptr> ImageVector;
190 };
191
192protected:
193 typedef std::vector<Octave> Octaves;
194
195protected:
196 void create_octaves (void);
197 void add_octave (mve::FloatImage::ConstPtr image,
198 float has_sigma, float target_sigma);
199 void extrema_detection (void);
200 std::size_t extrema_detection (mve::FloatImage::ConstPtr s[3],
201 int oi, int si);
202 void keypoint_localization (void);
203
204 void descriptor_generation (void);
205 void generate_grad_ori_images (Octave* octave);
206 void orientation_assignment (Keypoint const& kp,
207 Octave const* octave, std::vector<float>& orientations);
208 bool descriptor_assignment (Keypoint const& kp, Descriptor& desc,
209 Octave const* octave);
210
211 float keypoint_relative_scale (Keypoint const& kp);
212 float keypoint_absolute_scale (Keypoint const& kp);
213
214private:
215 Options options;
216 mve::FloatImage::ConstPtr orig; // Original input image
217 Octaves octaves; // The image pyramid (the octaves)
218 Keypoints keypoints; // Detected keypoints
219 Descriptors descriptors; // Final SIFT descriptors
220};
221
222/* ---------------------------------------------------------------- */
223
224inline
225Sift::Options::Options (void)
226 : num_samples_per_octave(3)
227 , min_octave(0)
228 , max_octave(4)
229 , contrast_threshold(-1.0f)
230 , edge_ratio_threshold(10.0f)
231 , base_blur_sigma(1.6f)
232 , inherent_blur_sigma(0.5f)
233 , verbose_output(false)
234 , debug_output(false)
235{
236}
237
238inline Sift::Keypoints const&
240{
241 return this->keypoints;
242}
243
244inline Sift::Descriptors const&
246{
247 return this->descriptors;
248}
249
251
252#endif /* SFM_SIFT_HEADER */
Vector class for arbitrary dimensions and types.
Definition vector.h:87
std::shared_ptr< Image< T > const > ConstPtr
Definition image.h:43
Implementation of the SIFT feature detector and descriptor.
Definition sift.h:43
std::vector< Keypoint > Keypoints
Definition sift.h:152
Descriptors const & get_descriptors(void) const
Returns the list of descriptors.
Definition sift.h:245
std::vector< Octave > Octaves
Definition sift.h:193
std::vector< Descriptor > Descriptors
Definition sift.h:153
Keypoints const & get_keypoints(void) const
Returns the list of keypoints.
Definition sift.h:239
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
Representation of the SIFT descriptor.
Definition sift.h:138
math::Vector< float, 128 > data
The descriptor data, elements are unsigned in [0.0, 1.0].
Definition sift.h:148
float scale
The scale (or sigma value) of the keypoint.
Definition sift.h:144
float orientation
The orientation of the image keypoint in [0, 2PI].
Definition sift.h:146
float x
The sub-pixel x-coordinate of the image keypoint.
Definition sift.h:140
float y
The sub-pixel y-coordinate of the image keypoint.
Definition sift.h:142
Representation of a SIFT keypoint.
Definition sift.h:121
float x
Keypoint x-coordinate.
Definition sift.h:127
float y
Keypoint y-coordinate.
Definition sift.h:129
int octave
Octave index of the keypoint.
Definition sift.h:123
float sample
Sample index.
Definition sift.h:125
Representation of a SIFT octave.
Definition sift.h:184
ImageVector grad
S+3 gradient images.
Definition sift.h:188
ImageVector dog
S+2 difference of gaussian images.
Definition sift.h:187
ImageVector ori
S+3 orientation images.
Definition sift.h:189
std::vector< mve::FloatImage::Ptr > ImageVector
Definition sift.h:185
ImageVector img
S+3 images per octave.
Definition sift.h:186
SIFT options.
Definition sift.h:49
float edge_ratio_threshold
Sets the edge threshold to eliminate edge responses.
Definition sift.h:84
bool debug_output
Produce even more messages on the console.
Definition sift.h:108
float base_blur_sigma
Sets the amount of desired base blur before constructing the octaves.
Definition sift.h:92
bool verbose_output
Produce status messages on the console.
Definition sift.h:103
float inherent_blur_sigma
Sets the inherent blur sigma in the input image.
Definition sift.h:98
float contrast_threshold
Sets contrast threshold, i.e.
Definition sift.h:77
int max_octave
Sets the maximum octave.
Definition sift.h:70
int num_samples_per_octave
Sets the amount of samples per octave.
Definition sift.h:56
int min_octave
Sets the minimum octave ID.
Definition sift.h:64