Optimization of sigma computation in OpenCV 2.4.8 SIFT implementation (Bug #3625)


Added by Chris Garry almost 11 years ago. Updated almost 11 years ago.


Status:Done Start date:2014-03-28
Priority:Normal Due date:
Assignee:Chris Garry % Done:

100%

Category:core
Target version:2.4.9
Affected version:branch 'master' (3.0-dev) Operating System:Mac OSX
Difficulty:Easy HW Platform:Any
Pull request:

Description

In the nonfree model, sift.cpp file, SIFT::buildGaussianPyramid method, lines 219 - 226:


// precompute Gaussian sigmas using the following formula:
// \sigma_{total}^2 = \sigma_{i}^2 + \sigma_{i-1}^2
sig[0] = sigma;
double k = pow( 2., 1. / nOctaveLayers );
for( int i = 1; i < nOctaveLayers + 3; i++ )
{
    double sig_prev = pow(k, (double)(i-1))*sigma;
    double sig_total = sig_prev*k;
    sig[i] = std::sqrt(sig_total*sig_total - sig_prev*sig_prev);
}

This can be optimized to:

  /*
precompute Gaussian sigmas using the following formula:
\sigma_{total}^2 = \sigma_{i}^2 + \sigma_{i-1}^2
sig[i] is the incremental sigma value needed to compute
the actual sigma of level i. Keeping track of incremental
sigmas vs. total sigmas keeps the gaussian kernel small.
*/
k = pow( 2.0, 1.0 / intvls );
sig[0] = sigma;
sig[1] = sigma * sqrt( k*k- 1 );
for (i = 2; i < intvls + 3; i++)
    sig[i] = sig[i-1] * k;

I added clarifying comments to this block of code because a bug report was incorrectly opened (see http://code.opencv.org/issues/3585) and assigned. I just closed that medium bug report. It was made due to confusion in understanding what exactly the code is doing which I clarified in the comments on that request.


Associated revisions

Revision b49fa7d3
Added by Vadim Pisarevsky about 10 years ago

Merge pull request #3625 from wangyan42164:ocl_cascade_deadlock

History

Updated by Chris Garry almost 11 years ago

Correction to above: intvls == nOctaveLayers. Also, using std:: for math library functions.

Updated by Chris Garry almost 11 years ago

  • Status changed from New to Done

Also available in: Atom PDF