Thanks for providing such a handsome sift code. But I really could not figure out why you calculate keypoint.octave like this
keypoint.octave = octave_index + image_index * (2 ** 8) \
+ int(round((extremum_update[2] + 0.5) * 255)) * (2 ** 16)
Thanks.