/* This searches through the keypoints in klist for the two closest matches to key. If the closest is less than 0.6 times distance to second closest, then return the closest match. Otherwise, return NULL. */ Keypoint CheckForMatch(Keypoint key, Keypoint klist) { int dsq, distsq1 = 100000000, distsq2 = 100000000; Keypoint k, minkey = NULL; /* Find the two closest matches, and put their squared distances in distsq1 and distsq2. */ for (k = klist; k != NULL; k = k->next) { dsq = DistSquared(key, k); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; minkey = k; } else if (dsq < distsq2) { distsq2 = dsq; } } /* Check whether closest distance is less than 0.6 of second. */ if (10 * 10 * distsq1 < 6 * 6 * distsq2) return minkey; else return NULL; }
/* This searches through the keypoints in klist for the two closest matches to key. It returns the ratio of the distance to key of the closest and next to closest keypoints in klist, while bestindex is the index of the closest keypoint. */ float CheckForMatch( keypoint& key, keypointslist& klist, keypointslist::size_type& min,siftPar &par) { float dsq, distsq1, distsq2; distsq1 = distsq2 = 1000000000000.0f; for (keypointslist::size_type j=0; j< klist.size(); j++){ dsq = DistSquared(key, klist[j], distsq2,par); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; min = j; } else if (dsq < distsq2) distsq2 = dsq; } return distsq1/distsq2 ; }
/** * This searches through the keypoints in klist for the two closest * matches to key. If the closest is less than 0.8 times distance to * second closest, then return the closest match. Otherwise, return * NULL. * * @return The closest key or NULL if no match was found. */ Keypoint CheckForMatch(Keypoint key, Keypoint klist) { int dsq, distsq1 = 100000000, distsq2 = 100000000; Keypoint k, minkey = NULL; for (k = klist; k != NULL; k = k->next) { dsq = DistSquared(key, k); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; minkey = k; } else if (dsq < distsq2) { distsq2 = dsq; } } if (100 * distsq1 < 80 * distsq2) { return minkey; } else return NULL; }
/* This searches through the keypoints in klist for the two closest matches to key. It returns the ratio of the distance to key of the closest and next to closest keypoints in klist, while bestindex is the index of the closest keypoint. */ float CheckForMatch( keypoint& key, keypointslist& klist, int& min,siftPar &par) { int nexttomin = -1; float dsq, distsq1, distsq2; distsq1 = distsq2 = 1000000000000.0f; for (int j=0; j< (int) klist.size(); j++){ dsq = DistSquared(key, klist[j], distsq2,par); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; nexttomin = min; min = j; } else if (dsq < distsq2) { distsq2 = dsq; nexttomin = j; } } return distsq1/distsq2 ; }