Itseez/opencv — pull request #2530 by chrislgarry (2014-03-26 03:42:40+00:00)
Title: Fixed "Logical flaw in OpenCV 2.4.8 SIFT implementation (Bug #3585)"

I realized after fixing that this was intially assigned to Vadim Pisarevsky. This is my first time contributing so I apologize. I'm still learning how the system works.

For an input image Z, a Gaussian pyramid is a stack or 'pyramid' of increasingly blurred (aka smoothed), scaled versions of Z by means of convolution with a Gaussian kernel. The resulting blurred image at each level is also scaled to yield a pyramid-like structure (not depicted below). The successive blurring means that the Gaussian kernel used to blur at each stage must increase in the rate of blurring/smoothing, which is done by scaling the sigma value or standard deviation of the Gaussian kernel by a factor k, which is sqrt(2). According to Lowe, the sigma value at level i is sigma(i) = k*sigma(i-1). This means for level n, sigma(n) = k^n*sigma(0). This can be seen in the image below taken from [2]. It is increased by multiplying the standard deviation by a power of the scaling factor. The issue in the code was that the first level sigma value was computed twice, so the first and second levels (sigma(0), sigma(1)) were always the same when sigma(1) should have been k*sigma(0). Due to this duplication, the rest of the sigma values were correct but were for in the incorrect indices (i.e. for the previous pyramid level).

![screen shot 2014-03-25 at 10 14 45 pm](https://f.cloud.github.com/assets/2200898/2520504/cd2448d6-b48c-11e3-99da-dd58c32d3744.png)

[1] http://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf
[3] http://www.cs.ucf.edu/courses/cap4453/sift/siftppt.ppt