Ask Your Question

KeyPoints&DMatch - What does distance stands for?

asked 2013-12-17 06:34:48 -0600

Viatorus gravatar image

updated 2013-12-17 06:45:59 -0600

Hey Community,

I don´t understand the parameter distance in the struct DMatch.

There is often the code for get only the "good matches":

double max_dist = 0;
double min_dist = 100;
for( int i = 0; i < descriptors.rows; i++ ){
 double dist = matches[i].distance; 
 if( dist < min_dist ) min_dist = dist; 
 if( dist > max_dist ) max_dist = dist;
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors.rows; i++ ){ 
 if( matches[i].distance <= 2*min_dist ) { 
  good_matches.push_back( matches[i]); 

But distance? What is this? It is a float, less than 1. But I can´t get a context between the distance and the pixel to pixel distance.

Say, a DMatch has his query by pixel (25, 50) [first image] and his train by (35, 50) [second image]. For me, the distance would be 10... DMatch.distance is something alá 0.065. And another distance comparison would be pixel (30, 65) and (40, 65). Again 10 pixel but DMatch.distance would be 0.062?!?

Anyone can help me, please?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2013-12-17 08:25:59 -0600

Moster gravatar image

updated 2013-12-17 08:27:07 -0600

This highly depends on what kind of matcher you use. For example bruteforce matching returns the hamming distance of those matched keypoints which equals integer numbers from 0 to infinity (actually limited by the length/bits of/in the descriptor). So there is no direct answer to your question if you dont tell us what kind of matcher (and descriptor) you used.

edit flag offensive delete link more

Comments I correct, that the distance doesn´t say me the pixel position (row, column) offset. It say me the pixel to pixel difference. So if query is COLOR(255,0,0) and the train would be (254,0,0) the hamming distance would be 1.... for me distance was a measure of length.

Viatorus gravatar imageViatorus ( 2013-12-17 08:49:00 -0600 )edit

@Viatorus: exactly, you got it!

Guanta gravatar imageGuanta ( 2013-12-17 08:57:10 -0600 )edit

Sorry for the late answer. The example with the color is kind of bad. A descriptor is usually not a color/intensitiy. This would be too sensitive towards any kind of noise, etc. You really need to look at what the descriptors actually do. For example, SIFT calculates the histogram of gradients of a certain patch(es) around the keypoint. To compare 2 SIFT desriptors, you actually use the euclidean distance, but on the descriptor and not the keypoint location. So this distance is not a geometric distance. In the end, the distance really depends on what kind of descriptor you use (and of course of the matcher which you apply according to the type of descriptor).

Moster gravatar imageMoster ( 2013-12-20 12:09:29 -0600 )edit

Check out this answer from stackoverflow which explains distance in DMatch elegantly.

questerer gravatar imagequesterer ( 2017-12-20 01:43:08 -0600 )edit

Question Tools


Asked: 2013-12-17 06:34:48 -0600

Seen: 2,560 times

Last updated: Dec 17 '13