Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORB test points file should be read in x-y and not r-c #7409

Open
flauted opened this issue May 3, 2024 · 0 comments
Open

ORB test points file should be read in x-y and not r-c #7409

flauted opened this issue May 3, 2024 · 0 comments
Labels

Comments

@flauted
Copy link

flauted commented May 3, 2024

Description:

Is it possible that the ORB test points file is meant to be read as x, y, x, y and not row, column, row, column?

I am referring to skimage/feature/orb_descriptor_positions.txt, which contains the same values as OpenCV lists in orb.cpp#L382-L637. I put together a code snippet below to plot the test point pairs and I noticed the following. When I run the steps-to-reproduce code that I have provided, I am seeing the following:

image

When I look at the ORB paper, Fig. 6, I expect the group of nearly-parallel tests to be aligned with the reference orientation.

Screenshot from 2024-05-03 09-21-57

When I change

            pr0 = cpos0[j, 0]
            pc0 = cpos0[j, 1]
            pr1 = cpos1[j, 0]
            pc1 = cpos1[j, 1]

to

            pr0 = cpos0[j, 1]
            pc0 = cpos0[j, 0]
            pr1 = cpos1[j, 1]
            pc1 = cpos1[j, 0]

I see what I am expecting:

image

Maybe I am misinterpreting the paper or reading the code wrong?

Way to reproduce:

import numpy as np
from numpy import sin, cos
import matplotlib.pyplot as plt
import skimage as ski
import os

# modeled after https://github.com/scikit-image/scikit-image/blob/v0.23.2/skimage/feature/_orb_descriptor_positions.py
this_dir = "."
POS = np.loadtxt(os.path.join(this_dir, "orb_descriptor_positions.txt"), dtype=np.int8)
POS0 = np.ascontiguousarray(POS[:, :2])
POS1 = np.ascontiguousarray(POS[:, 2:])

# closely modeled after https://github.com/scikit-image/scikit-image/blob/v0.23.2/skimage/feature/orb_cy.pyx
def _orb_loop(image, keypoints, orientations):
    test_points = np.zeros((POS.shape[0], 4), dtype=np.float64)  # my addition to collect the test points

    descriptors = np.zeros(
        (keypoints.shape[0], POS.shape[0]), dtype=np.uint8)
    cpos0 = POS0
    cpos1 = POS1

    for i in range(descriptors.shape[0]):

        angle = orientations[i]
        sin_a = sin(angle)
        cos_a = cos(angle)

        kr = keypoints[i, 0]
        kc = keypoints[i, 1]

        for j in range(descriptors.shape[1]):
            pr0 = cpos0[j, 0]
            pc0 = cpos0[j, 1]
            pr1 = cpos1[j, 0]
            pc1 = cpos1[j, 1]

            spr0 = round(sin_a * pr0 + cos_a * pc0)
            spc0 = round(cos_a * pr0 - sin_a * pc0)
            spr1 = round(sin_a * pr1 + cos_a * pc1)
            spc1 = round(cos_a * pr1 - sin_a * pc1)

            test_points[j] = [kr + spr0, kc + spc0, kr + spr1, kc + spc1]  # my addition to collect the test points

            if image[kr + spr0, kc + spc0] < image[kr + spr1, kc + spc1]:
                descriptors[i, j] = True

    return test_points

chip_size = 41
image = np.zeros((chip_size, chip_size), dtype=np.uint8)
image[0:-chip_size//2, 0:-chip_size//2] = 255

orb = ski.feature.ORB(n_keypoints=1)
orb.detect(image)
test_points = _orb_loop(image, orb.keypoints.round().astype(np.int64), orb.orientations)

# show the test point pairs
plt.imshow(image, cmap="gray")
for j in range(test_points.shape[0]):
    r1, c1, r2, c2 = test_points[j]
    x1, y1 = c1, r1
    x2, y2 = c2, r2
    plt.plot([x1, x2], [y1, y2])

# display the orientation
for k in range(orb.keypoints.shape[0]):
    plt.arrow(orb.keypoints[k,0], orb.keypoints[k,1], 20*cos(orb.orientations[k]), 20*sin(orb.orientations[k]), head_width=1)

Version information:

3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0]
Linux-6.5.0-1020-oem-x86_64-with-glibc2.35
scikit-image version: 0.22.0
numpy version: 1.26.4
@flauted flauted changed the title ORB keypoints should be read in x-y and not r-c ORB test points file should be read in x-y and not r-c May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant