diff --git a/src/application/main.cpp b/src/application/main.cpp index e4da6757..689c5a01 100755 --- a/src/application/main.cpp +++ b/src/application/main.cpp @@ -113,8 +113,6 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in "Computed filter width are lower than VLFeat/PopSift") ("direct-scaling", bool_switch()->notifier([&](bool b) { if(b) config.setScalingMode(popsift::Config::ScaleDirect); }), "Direct each octave from upscaled orig instead of blurred level.") - ( "ori-mode", value()->notifier([&](const std::string& s) {config.setOrientationMode(s); }), - popsift::Config::getOrientationModeUsage() ) ("norm-multi", value()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,).") ( "norm-mode", value()->notifier([&](const std::string& s) { config.setNormMode(s); }), popsift::Config::getNormModeUsage() ) diff --git a/src/popsift/s_orientation.cu b/src/popsift/s_orientation.cu index a2f24f28..96d43049 100644 --- a/src/popsift/s_orientation.cu +++ b/src/popsift/s_orientation.cu @@ -45,101 +45,11 @@ float smoothe( const float* const src, const int bin ) return f; } -class BestBin -{ -public: - __device__ inline static - void fillHist( float* hist, const float weight, const float theta ) - { - int bidx = (int)roundf( __fdividef( float(ORI_NBINS) * (theta + M_PI), M_PI2 ) ); - - while( bidx < 0 ) bidx += ORI_NBINS; - while( bidx >= ORI_NBINS ) bidx -= ORI_NBINS; - - atomicAdd( &hist[bidx], weight ); - } - - __device__ inline static - void refine( int bin, float* hist, float maxval, float& angle, float& val ) - { - const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS; - const int next = ( bin + 1 ) % ORI_NBINS; - - bool predicate = ( bin < ORI_NBINS ) && - ( hist[bin] > max( hist[prev], hist[next] ) ) && - ( hist[bin] > 0.8f * maxval ); - - const float num = predicate ? 3.0f * hist[prev] - - 4.0f * hist[bin] - + 1.0f * hist[next] - : 0.0f; - const float denB = predicate ? 2.0f * ( hist[prev] - 2.0f * hist[bin] + hist[next] ) : 1.0f; - - const float newbin = __fdividef( num, denB ); // verified: accuracy OK - - angle = predicate ? prev + newbin : -1; - val = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY; - } - - __device__ inline static - float twist( float angle ) - { - angle -= M_PI; - if( angle < 0 ) angle += M_PI2; - return angle; - } -}; - -class InterpolatedBin -{ -public: - __device__ inline static - void fillHist( float* hist, const float weight, const float theta ) - { - const float fbin = float(ORI_NBINS) / M_PI2 * theta; - const int bin = (int)floorf(fbin - 0.5f); - const float rbin = fbin - bin - 0.5f; - - int bin1 = ( bin + ORI_NBINS ) % ORI_NBINS; - atomicAdd( &hist[bin1], (1.0f - rbin) * weight ); - int bin2 = ( bin + 1 ) % ORI_NBINS; - atomicAdd( &hist[bin2], rbin * weight ); - } - - __device__ inline static - void refine( int bin, float* hist, float maxval, float& angle, float& val ) - { - const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS; - const int next = ( bin + 1 ) % ORI_NBINS; - - bool predicate = ( bin < ORI_NBINS ) && - ( hist[bin] > max( hist[prev], hist[next] ) ) && - ( hist[bin] > 0.8f * maxval ); - - const float num = predicate ? hist[next] - hist[prev] - : 0.0f; - const float denB = predicate ? 2.0f * ( hist[prev] - 2.0f * hist[bin] + hist[next] ) : 1.0f; - - const float newbin = __fdividef( num, denB ); // verified: accuracy OK - - angle = predicate ? bin + newbin + 0.5f : -1; - - val = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY; - } - - __device__ inline static - float twist( float angle ) - { - return angle; - } -}; - /* * Compute the keypoint orientations for each extremum * using 16 threads for each of them. * direct curve fitting approach */ -template __global__ void ori_par( const int octave, const int ext_ct_prefix_sum, @@ -170,7 +80,6 @@ void ori_par( const int octave, /* orientation histogram radius */ const float sigw = ORI_WINFACTOR * sig; - // const int32_t rad = (int)roundf((3.0f * sigw)); const int32_t rad = max( (int)floorf((3.0f * sigw)), 1 ); const float factor = __fdividef( -0.5f, (sigw * sigw) ); @@ -216,7 +125,12 @@ void ori_par( const int octave, { float weight = grad * expf(sq_dist * factor); - SB::fillHist( hist, weight, theta ); + int bidx = (int)roundf( __fdividef( float(ORI_NBINS) * (theta + M_PI), M_PI2 ) ); + + while( bidx < 0 ) bidx += ORI_NBINS; + while( bidx >= ORI_NBINS ) bidx -= ORI_NBINS; + + atomicAdd( &hist[bidx], weight ); } } } @@ -251,7 +165,23 @@ void ori_par( const int octave, for( int bin = threadIdx.x; popsift::any( bin < ORI_NBINS ); bin += blockDim.x ) { - SB::refine( bin, sm_hist, maxval, refined_angle[bin], yval[bin] ); + const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS; + const int next = ( bin + 1 ) % ORI_NBINS; + + bool predicate = ( bin < ORI_NBINS ) && + ( sm_hist[bin] > max( sm_hist[prev], sm_hist[next] ) ) && + ( sm_hist[bin] > 0.8f * maxval ); + + const float num = predicate ? 3.0f * sm_hist[prev] + - 4.0f * sm_hist[bin] + + 1.0f * sm_hist[next] + : 0.0f; + const float denB = predicate ? 2.0f * ( sm_hist[prev] - 2.0f * sm_hist[bin] + sm_hist[next] ) : 1.0f; + + const float newbin = __fdividef( num, denB ); // verified: accuracy OK + + refined_angle[bin] = predicate ? prev + newbin : -1; + yval[bin] = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY; } __syncthreads(); @@ -274,7 +204,8 @@ void ori_par( const int octave, if( chosen_bin >= ORI_NBINS ) chosen_bin -= ORI_NBINS; if( chosen_bin < 0 ) chosen_bin += ORI_NBINS; float th = __fdividef(M_PI2 * chosen_bin , ORI_NBINS); // - M_PI; - th = SB::twist( th ); + th -= M_PI; + if( th < 0.0f ) th += M_PI2; ext->orientation[threadIdx.x] = th; written = true; } @@ -443,26 +374,13 @@ void Pyramid::orientation( const Config& conf ) block.y = 1; grid.x = num; - if( conf.getOrientationMode() == Config::BestBin ) - { - ori_par - <<>> - ( octave, - hct.ext_ps[octave], - oct_obj.getDataTexPoint( ), - oct_obj.getWidth( ), - oct_obj.getHeight( ) ); - } - else - { - ori_par - <<>> - ( octave, - hct.ext_ps[octave], - oct_obj.getDataTexPoint( ), - oct_obj.getWidth( ), - oct_obj.getHeight( ) ); - } + ori_par + <<>> + ( octave, + hct.ext_ps[octave], + oct_obj.getDataTexPoint( ), + oct_obj.getWidth( ), + oct_obj.getHeight( ) ); POP_SYNC_CHK; if( octave != 0 ) { diff --git a/src/popsift/sift_conf.cu b/src/popsift/sift_conf.cu index 2690e97e..aedbd458 100644 --- a/src/popsift/sift_conf.cu +++ b/src/popsift/sift_conf.cu @@ -34,7 +34,6 @@ Config::Config( ) , _sift_mode( Config::PopSift ) , _log_mode( Config::None ) , _scaling_mode( Config::ScaleDefault ) - , _ori_mode( Config::OriDefault ) , _desc_mode( Config::Loop ) , _grid_filter_mode( Config::RandomScale ) , verbose( false ) @@ -196,42 +195,6 @@ void Config::setScalingMode( ScalingMode mode ) _scaling_mode = mode; } -void Config::setOrientationMode( OriMode mode ) -{ - _ori_mode = mode; -} - -void Config::setOrientationMode( const std::string& text ) -{ - if( stringIsame( text, "BestBin" ) ) - { - _ori_mode = BestBin; - } - else if( stringIsame( text, "PopSift" ) ) - { - _ori_mode = BestBin; - } - else if( stringIsame( text, "InterpolatedBin" ) ) - { - _ori_mode = InterpolatedBin; - } - else if( stringIsame( text, "VLFeat" ) ) - { - _ori_mode = InterpolatedBin; - } - else - POP_FATAL( string("Bad Orientation mode.\n") + getOrientationModeUsage() ); -} - -const char* Config::getOrientationModeUsage( ) -{ - return - "Choice of orientation computation modes. " - "Options are: " - "BestBin (original PopSift bejaviour, default), " - "InterpolatedBin (VLFeat-like behaviour, experimental, do not use)"; -} - /** * Normalization mode * Should the descriptor normalization use L2-like classic normalization diff --git a/src/popsift/sift_conf.h b/src/popsift/sift_conf.h index 620152cc..9f78d12b 100644 --- a/src/popsift/sift_conf.h +++ b/src/popsift/sift_conf.h @@ -80,24 +80,6 @@ struct Config ScaleDefault }; - /** - * @brief PopSift - */ - enum OriMode - { - /** One bin per sample in histogram filling, quadratic angle refinement. - * Original mode using by PopSift. - */ - BestBin, - /** Two bins per sample in histogram filling, simple angle refinement. - * Tries to implement the approach taken by VLFeat. Experimental. - */ - InterpolatedBin, - /// default value - OriDefault = BestBin - - }; - /** * @brief Modes for descriptor extraction. */ @@ -193,20 +175,6 @@ struct Config */ void setScalingMode( ScalingMode mode = ScaleDefault ); - /** - * @brief Set the orientation mode. - * @param mode The orientation mode - * @see OriMode - */ - void setOrientationMode( OriMode mode = BestBin ); - - /** - * @brief Set the orientation mode. - * @param text string parsed as a legal orientation mode - * @see OriMode - */ - void setOrientationMode( const std::string& text ); - /** * @brief Enable/desable verbose mode. * @param[in] on Whether to display additional information . @@ -388,18 +356,6 @@ struct Config */ inline ScalingMode getScalingMode() const { return _scaling_mode; } - /** - * @brief Get the orientation mode. - * @return the orientation mode. - * @see OriMode - */ - inline OriMode getOrientationMode() const { return _ori_mode; } - - /** - * @brief Helper functions for the main program's usage string. - */ - static const char* getOrientationModeUsage( ); - /** * @brief Get the descriptor extraction mode * @return the descriptor extraction mode @@ -429,9 +385,6 @@ struct Config /// default: ScalingMode::DownscaledOctaves ScalingMode _scaling_mode; - /// default: OriMode::BestBin - OriMode _ori_mode; - /// default: DescMode::Loop DescMode _desc_mode;