rmislam/PythonSIFT

Calculation of number of Octaves

Vishnu-2695 opened this issue · 2 comments

def computeNumberOfOctaves(image_shape):
    """Compute number of octaves in image pyramid as function of base image shape (OpenCV default)
    """
    return int(round(log(min(image_shape)) / log(2) - 1))

The function is called as such:

num_octaves = computeNumberOfOctaves(base_image.shape)

When I was executing these functions manually, I discovered that, taking min(image_shape) will lead to log(3)
(3 being the number of channels rather than smaller of the 2 dimensions).

My suggestion is that the return statement of the function should be:

return int(round(log(min(image_shape[:2])) / log(2) - 1))

Request you to verify if this logic is correct and make change if required.

Regards

Hi @Vishnu-2695 , SIFT is only defined for grayscale images (Lowe mentions it in his paper). If you see template_matching_demo.py in this repo, you can see on lines 10 and 11 that I read the images as grayscale images (the 0 flag is passed to cv2.imread):

img1 = cv2.imread('box.png', 0)           # queryImage
img2 = cv2.imread('box_in_scene.png', 0)  # trainImage

I'll leave the line you mention in pysift.py the way it is, because I think changing it to image_shape[:2] will lead to confusion and possibly make people think that more than two-channel images are supported. Instead at the beginning of the SIFT pipeline, I'll force grayscale conversion and add a comment.

I must of changed the order of execution for converting to grayscale images in my code.
Thank you for clarifying the doubt.