Skip to content

Commit 29a2da3

Browse files
author
Carsten Griwodz
committed
[feature] config for descriptor normalization mode changed
1 parent c71799d commit 29a2da3

File tree

4 files changed

+101
-22
lines changed

4 files changed

+101
-22
lines changed

src/application/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
9898
"Computed filter width are lower than VLFeat/PopSift")
9999
("direct-scaling", bool_switch()->notifier([&](bool b) { if(b) config.setScalingMode(popsift::Config::ScaleDirect); }),
100100
"Direct each octave from upscaled orig instead of blurred level.")
101-
("root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setUseRootSift(true); }),
102-
"Use the L1-based norm for OpenMVG rather than L2-based as in OpenCV")
103101
("norm-multi", value<int>()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,<int>).")
102+
( "norm-mode", value<std::string>()->notifier([&](const std::string& s) { config.setNormMode(s); }),
103+
popsift::Config::getNormModeUsage() )
104+
( "root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setNormMode(popsift::Config::RootSift); }),
105+
popsift::Config::getNormModeUsage() )
104106
("filter-max-extrema", value<int>()->notifier([&](int f) {config.setFilterMaxExtrema(f); }), "Approximate max number of extrema.")
105107
("filter-grid", value<int>()->notifier([&](int f) {config.setFilterGridSize(f); }), "Grid edge length for extrema filtering (ie. value 4 leads to a 4x4 grid)")
106108
("filter-sort", value<std::string>()->notifier([&](const std::string& s) {config.setFilterSorting(s); }), "Sort extrema in each cell by scale, either random (default), up or down");

src/application/match.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& lF
9797
"Computed filter width are lower than VLFeat/PopSift")
9898
("direct-scaling", bool_switch()->notifier([&](bool b) { if(b) config.setScalingMode(popsift::Config::ScaleDirect); }),
9999
"Direct each octave from upscaled orig instead of blurred level.")
100-
("root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setUseRootSift(true); }),
101-
"Use the L1-based norm for OpenMVG rather than L2-based as in OpenCV")
102100
("norm-multi", value<int>()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,<int>).")
101+
( "norm-mode", value<std::string>()->notifier([&](const std::string& s) { config.setNormMode(s); }),
102+
popsift::Config::getNormModeUsage() )
103+
( "root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setNormMode(popsift::Config::RootSift); }),
104+
popsift::Config::getNormModeUsage() )
103105
("filter-max-extrema", value<int>()->notifier([&](int f) {config.setFilterMaxExtrema(f); }), "Approximate max number of extrema.")
104106
("filter-grid", value<int>()->notifier([&](int f) {config.setFilterGridSize(f); }), "Grid edge length for extrema filtering (ie. value 4 leads to a 4x4 grid)")
105107
("filter-sort", value<std::string>()->notifier([&](const std::string& s) {config.setFilterSorting(s); }), "Sort extrema in each cell by scale, either random (default), up or down");

src/popsift/sift_conf.cu

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Config::Config( )
3434
, _filter_grid_size( 2 )
3535
, _assume_initial_blur( true )
3636
, _initial_blur( 0.5f )
37-
, _use_root_sift( true )
37+
, _normalization_mode( getNormModeDefault() )
3838
, _normalization_multiplier( 0 )
3939
, _print_gauss_tables( false )
4040
{
@@ -97,7 +97,7 @@ void Config::setGaussMode( const std::string& m )
9797
else if( m == "fixed15" )
9898
setGaussMode( Config::Fixed15 );
9999
else
100-
POP_FATAL( string("Bad Gauss mode.") + getGaussModeUsage() );
100+
POP_FATAL( string("Bad Gauss mode.\n") + getGaussModeUsage() );
101101
}
102102

103103
Config::GaussMode Config::getGaussModeDefault( )
@@ -165,15 +165,79 @@ void Config::setScalingMode( ScalingMode mode )
165165
_scaling_mode = mode;
166166
}
167167

168+
/**
169+
* Normalization mode
170+
* Should the descriptor normalization use L2-like classic normalization
171+
* of the typically better L1-like RootSift normalization?
172+
*/
173+
void Config::setUseRootSift( bool on )
174+
{
175+
if( on )
176+
_normalization_mode = RootSift;
177+
else
178+
_normalization_mode = Classic;
179+
}
180+
181+
bool Config::getUseRootSift( ) const
182+
{
183+
return ( _normalization_mode == RootSift );
184+
}
185+
186+
Config::NormMode Config::getNormMode( NormMode m ) const
187+
{
188+
return _normalization_mode;
189+
}
190+
191+
void Config::setNormMode( Config::NormMode m )
192+
{
193+
_normalization_mode = m;
194+
}
195+
196+
void Config::setNormMode( const std::string& m )
197+
{
198+
if( m == "RootSift" ) setNormMode( Config::RootSift );
199+
else if( m == "classic" ) setNormMode( Config::Classic );
200+
else
201+
POP_FATAL( string("Bad Normalization mode.\n") + getGaussModeUsage() );
202+
}
203+
204+
Config::NormMode Config::getNormModeDefault( )
205+
{
206+
return Config::RootSift;
207+
}
208+
209+
const char* Config::getNormModeUsage( )
210+
{
211+
return
212+
"Choice of descriptor normalization modes. "
213+
"Options are: "
214+
"RootSift (L1-like, default), "
215+
"Classic (L2-like)";
216+
}
217+
218+
/**
219+
* Normalization multiplier
220+
* A power of 2 multiplied with the normalized descriptor. Required
221+
* for the construction of 1-byte integer desciptors.
222+
* Usual choice is 2^8 or 2^9.
223+
*/
224+
void Config::setNormalizationMultiplier( int mul )
225+
{
226+
_normalization_multiplier = mul;
227+
}
228+
229+
int Config::getNormalizationMultiplier( ) const
230+
{
231+
return _normalization_multiplier;
232+
}
233+
168234
void Config::setDownsampling( float v ) { _upscale_factor = -v; }
169235
void Config::setOctaves( int v ) { octaves = v; }
170236
void Config::setLevels( int v ) { levels = v; }
171237
void Config::setSigma( float v ) { sigma = v; }
172238
void Config::setEdgeLimit( float v ) { _edge_limit = v; }
173239
void Config::setThreshold( float v ) { _threshold = v; }
174240
void Config::setPrintGaussTables() { _print_gauss_tables = true; }
175-
void Config::setUseRootSift( bool on ) { _use_root_sift = on; }
176-
void Config::setNormalizationMultiplier( int mul ) { _normalization_multiplier = mul; }
177241
void Config::setFilterMaxExtrema( int ext ) { _filter_max_extrema = ext; }
178242
void Config::setFilterGridSize( int sz ) { _filter_grid_size = sz; }
179243

@@ -233,7 +297,7 @@ bool Config::equal( const Config& other ) const
233297
COMPARE( _sift_mode ) ||
234298
COMPARE( _assume_initial_blur ) ||
235299
COMPARE( _initial_blur ) ||
236-
COMPARE( _use_root_sift ) ||
300+
COMPARE( _normalization_mode ) ||
237301
COMPARE( _normalization_multiplier ) ) return false;
238302
return true;
239303
}

src/popsift/sift_conf.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ struct Config
5757
NoTile // variant of IGrid, no duplicate gradiant fetching
5858
};
5959

60+
enum NormMode {
61+
RootSift, // The L1-inspired norm, gives better matching results
62+
Classic // The L2-inspired norm, all descriptors on a hypersphere
63+
};
64+
6065
/* To reduce time used in descriptor extraction, some extrema can be filtered
6166
* immediately after finding them. It is possible to keep those with the largest
6267
* scale (LargestScaleFirst), smallest scale (SmallestScaleFirst), or a random
@@ -96,11 +101,9 @@ struct Config
96101
void setEdgeLimit( float v );
97102
void setThreshold( float v );
98103
void setInitialBlur( float blur );
99-
void setUseRootSift( bool on );
100104
void setMaxExtreme( int m );
101105
void setPrintGaussTables( );
102106
void setDPOrientation( bool on );
103-
void setNormalizationMultiplier( int mul );
104107
void setMaxExtrema( int extrema );
105108
void setFilterMaxExtrema( int extrema );
106109
void setFilterGridSize( int sz );
@@ -151,9 +154,21 @@ struct Config
151154
// default edge_limit 10.0f from Bemap
152155
float _edge_limit;
153156

154-
inline bool getUseRootSift( ) const {
155-
return _use_root_sift;
156-
}
157+
/** Functions related to descriptor normalization: L2-like or RootSift
158+
*/
159+
void setNormMode( NormMode m );
160+
void setNormMode( const std::string& m );
161+
void setNormNode( const std::string& m );
162+
void setUseRootSift( bool on ) __attribute__ ((deprecated));
163+
bool getUseRootSift( ) const;
164+
NormMode getNormMode( NormMode m ) const;
165+
static NormMode getNormModeDefault( ); // Call this from the constructor.
166+
static const char* getNormModeUsage( ); // Helper functions for the main program's usage string.
167+
168+
/** Functions related to descriptor normalization: multiply with a power of 2
169+
*/
170+
int getNormalizationMultiplier( ) const;
171+
void setNormalizationMultiplier( int mul );
157172

158173
/* The input image is stretched by 2^upscale_factor
159174
* before processing. The factor 1 is default.
@@ -162,10 +177,6 @@ struct Config
162177
return _upscale_factor;
163178
}
164179

165-
int getNormalizationMultiplier( ) const {
166-
return _normalization_multiplier;
167-
}
168-
169180
int getMaxExtrema( ) const {
170181
return _max_extrema;
171182
}
@@ -275,17 +286,17 @@ struct Config
275286
bool _assume_initial_blur;
276287
float _initial_blur;
277288

278-
/* OpenMVG requires a normalization named rootSift.
279-
* Default is the OpenCV method.
289+
/* OpenMVG requires a normalization named rootSift, the
290+
* classical L2-inspired mode is also supported.
280291
*/
281-
bool _use_root_sift;
292+
NormMode _normalization_mode;
282293

283294
/* SIFT descriptors are normalized in a final step.
284295
* The values of the descriptor can also be multiplied
285296
* by a power of 2 if required.
286297
* Specify the exponent.
287298
*/
288-
int _normalization_multiplier;
299+
int _normalization_multiplier;
289300

290301
/* Call the debug functions in gauss_filter.cu to print Gauss
291302
* filter width and Gauss tables in use.

0 commit comments

Comments
 (0)