Optimization of sigma computation in OpenCV 2.4.8 SIFT implementation (Bug #3625)
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
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