Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SIFT Detection Octave Calculation

I'm not quite sure if i got the calculation of SIFT keypoint Detection. I looked into the nonfree/sift.cpp file in the SIFT::operator() and adjustLocalExtrema Method. There are some bitmask operations which allow to transport the fractional part of the octave to the SIFT Descriptor. Nevertheless i do not quite understand the data representation. In SIFT::operator() a local variable named firstOctave is initialized with -1 (line 731, nonfree/sift.cpp, branch 2.4). Then there are 2 possibilities: If useProvidedKeypoints == true, the following code is executed:

firstOctave = 0;
int maxOctave = INT_MIN;
for( size_t i = 0; i < keypoints.size(); i++ )
{
    int octave, layer;
    float scale;
    unpackOctave(keypoints[i], octave, layer, scale);
    firstOctave = std::min(firstOctave, octave);      // stays 0!
    maxOctave = std::max(maxOctave, octave);
    actualNLayers = std::max(actualNLayers, layer-2);
}

firstOctave = std::min(firstOctave, 0); // stays 0!

firstOctave is first overwritten zero and then by a min-Expression. Whatever octave will be, the value stays 0 (i run a test on this and octave never was <0).

The second posibility is when useProvidedKeypoints == false:

if( firstOctave < 0 ) // if useProvidedKeypoints  == false, firstOctave is ALWAYS -1!
    for( size_t i = 0; i < keypoints.size(); i++ )
    {
        KeyPoint& kpt = keypoints[i];
        float scale = 1.f/(float)(1 << -firstOctave);
        kpt.octave = (kpt.octave & ~255) | ((kpt.octave + firstOctave) & 255); // why adding -1 to the last byte?
        kpt.pt *= scale;
        kpt.size *= scale;
    }

This is the main issue. If useProvidedKeypoints == false the first code example will never be executet. So, firstOctave will be -1 everytime this second code will be executed. My Questions are:

  • Why is there the statement if( firstOctave < 0 ) when firstOvtave always is -1?
  • Why is the value of fistOctave added to the last Byte of kpt.octave if it is always -1? This results is octave == 255 in some cases (when the previous octave was 0) for the keypoint output.