0

My goal is to find the similarities between a truth image and an array of other images by using the opencv feature detection and matchings. So far things are going good, but I'm not sure what to do the the DMatch object.

I'm currently doing nearest neighbor on each sets of matches (given match.distance and location of the keypoint) to find the image with the least distance to the truth image. I some how feel like it's not a sophisticated approach.

Are there papers out there where researchers uses some kind of 'find the inverse feature matrix / get the identity matrix' method?

simple sample of for each match:

        # similarity distance
        sim_dist = mat.distance

        # location difference
        (x_1, y_1) = k_p1[img1_idx].pt
        (x_2, y_2) = k_p2[img2_idx].pt

        loc_dist = np.linalg.norm(np.subtract((x_1, y_1), (x_2, y_2)))
        result += loc_dist * sim_dist

As you can see, the smaller the result value is, the more similar the images are.

Thanks.

Pibben
  • 1,876
  • 14
  • 28
Jordan Huang
  • 25
  • 1
  • 8
  • and do you need the keypoints of the images to be exactly in the same position (for a perfect match), as of original image ? or it can be slightly translated or scaled ? – venkata krishnan Oct 09 '19 at 01:20
  • keypoints don't need to be in the same location since each image is slightly translated / scaled / rotated.. But only very slightly. All images are the same size. btw, the end result will be divided by the amount of matches found. – Jordan Huang Oct 09 '19 at 21:31
  • Therefore I'm assuming if a feature exists in the truth, the next closest image should have the same feature detected in a similar location – Jordan Huang Oct 09 '19 at 21:37
  • so for a naive alogrithm will be, finding the nearest keypoints and measuring the distance between these two and adding up, and finally normalizing it by the number of keypoints, which will result in a score between 0 to 1 ? where 1 being highly dissimilar? – venkata krishnan Oct 10 '19 at 01:20

1 Answers1

0

I think it's an reasonable approach. However, you need to take into account the dimensionality and scale of your different distance measures.

The DMatch distance measure can be euclidian (in feature space) or the Hamming distance, depending on the type of descriptor. See What does the distance attribute in DMatches mean?.

This means you have to find a weight to balance between the feature-space distance and the spatial distance, that incorporates both the difference in scale of the measures and the relative importance of "close in feature space" and "spatially close."

Something like this:

    # similarity distance
    sim_dist = mat.distance

    # location difference
    (x_1, y_1) = k_p1[img1_idx].pt
    (x_2, y_2) = k_p2[img2_idx].pt

    loc_dist = np.linalg.norm(np.subtract((x_1, y_1), (x_2, y_2)))

    weight = 1000.0

    result += loc_dist * weight + sim_dist

The actual weight is dependent on the application and is probably easiest to find by trial-and-error.

Pibben
  • 1,876
  • 14
  • 28