What does the distance attribute in DMatches mean?

16,981

Solution 1

In this context, a feature is a point of interest on the image. In order to compare features, you "describe" them using a feature detector. Each feature is then associated to a descriptor. When you match features, you actually match their descriptors.

A descriptor is a multidimensional vector. It can be real-valued (e.g. SIFT) or binary (e.g. BRIEF).

A matching is a pair of descriptors, one from each image, which are the most similar among all of the descriptors. And of course, to find the descriptor in image B that is the most similar to a descriptor in image A, you need a measure of this similarity.

There are multiple ways to compute a "score of similarity" between two vectors. For real-valued descriptors, the Euclidean distance is often used, when the Hamming distance is common for binary descriptors.

As a conclusion, we can now understand the distance attribute: it is the score of similarity between the two descriptors of a match.

Solution 2

Distance attribute in DMatch is a measure of similarity between the two descriptors(feature vectors). If the distance is less, then the images are more similar and vice versa.

A lesson learnt from my experience when I started out:

Do not confuse the DMatch.distance with the normal spatial distance between two points. Both are different. The distance in the DMatch represents the distance between two descriptors(vectors with 128 values in case of SIFT)

In case of SIFT (local feature descriptor):

1) First, you detect key points(interesting points) for the two images that you want to compare.

2) Then you compute sift descriptors for a defined area (16 X 16 neighbourhood around each key point) around all the key points. Each descriptor stores the histogram of oriented gradients for the area around each key point.

3) Finally, the descriptors of both the images are matched to find matching key points between the images. This is done by using BFMatcher -> match(), knnMatch() or FlannBasedMatcher -> knnMatch().

4) If you are using BFMatcher.match(), you will get a list of DMatch objects. The number of DMatch objects is equal to the number of matches. Each DMatch object contains following four attributes for each matched key point pair.

DMatch.distance - Distance between descriptors. The lower, the better it is.
DMatch.trainIdx - Index of the descriptor in train descriptors(1st image)
DMatch.queryIdx - Index of the descriptor in query descriptors(2nd image)
DMatch.imgIdx - Index of the train image.

5) DMatch.Distance can be one of many distance measures -> Norm_L1, Norm_L2(Euclidean distance), Hamming distance, Hamming2 distance,... which can be mentioned as a parameter in BFMatcher. The Default distance is Euclidean.

6) Difference between Spatial Euclidean distance and DMatch Euclidean distance:

SIFT descriptor 1 -> [a1,a2,....a128]

SIFT descriptor 2 -> [b1,b2,....b128]

(DMatch) -> Euclidean distance = sqrt[(a1-b1)^2 + (a2-b2)^2 +...+(a128-b128)^2]

Point 1 -> (x1, y1)

Point 2 -> (x2, y2)

(Spatial) -> Euclidean distance = sqrt[(x2-x1)^2 + (y2-y1)^2]

Thus, this distance from DMatch is the distance between descriptors and it represents the degree of similarity between two descriptors and is different from the normal spatial euclidean distance between two points.

If the distance between the descriptors is less, then their similarity is high. If the distance between the descriptors is more, then their similarity is low.

Hope this helps in understanding the meaning of distance attribute in DMatch objects. If you are clear on this, then you can work with any feature descriptors like HOG, SIFT, SURF, ORB, BRISK, FREAK,... All of them are similar when it comes to matching their respective feature descriptors.

Solution 3

Usually when you are matching two features, you are actually comparing two vectors under certain distance metrics. Now let's assume your feature is SIFT with 128 dimensions, and you compare two SIFT features a and b using Euclidean distance, then DMatch.distance is equal to

formula

Share:
16,981

Related videos on Youtube

stetro
Author by

stetro

Updated on June 25, 2022

Comments

  • stetro
    stetro almost 2 years

    I have a short question: When I do feature-matching in OpenCV, what does the distance attribute mean of DMatches in MatOfMatches?

    I know that I have to filter matches with bigger distance because they aren't as good as them with lower distance. But what is the meaning of this attribute? Is it a kind of deviation?

  • stetro
    stetro almost 11 years
    One short question left, why do the matching algorithems gives me matches with big distance when they obviously not be identically?
  • JonasVautherin
    JonasVautherin almost 11 years
    They give the best match w.r.t the descriptors you have. Some are correct, some aren't. Different techniques exist to filter out the outliers, but the best one depends on the situation and this is not the job of the matcher itself...
  • rbaleksandar
    rbaleksandar about 10 years
    Can you please elaborate on the part about "A descriptor is a multidimensional vector" - it is indeed a matrix but what exactly do the single elements in it represent?
  • rbaleksandar
    rbaleksandar about 10 years
    I've read that a descriptor basically "captures" the intensity around a keypoint, which means that the descriptor matrix basically stores for each keypoint all the intensities where this keypoint has been detected. If we have keypoint A that is found in our image 10 times, then the row for this keypoint in the descriptor matrix will contain 10 intensity values. Is this correct or am I completely misunderstanding the whole thing?
  • Lenar Hoyt
    Lenar Hoyt over 8 years
    Distance is actually a measure of dissimilarity.
  • Angie Quijano
    Angie Quijano about 8 years
    I have a question. When you say "score", has that number limits?. I mean that score is number between 0 and 1, or something like that?.