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?
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.
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.
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
Related
The algorithm for the K-means++ is:
Take one centroid c(i), chosen uniformly at random from the dataset.
Take a new Centroid c(i), choosing an instance x(i) from the dataset with the probability
D(X(i))^2/Sum(D(X(j))^2) from j=1 to m, where D(X(i)) is the distance between the instance and the closest centroid which is selected.
What is this parameter m used in the summation of the probability?
It might have been helpful to see the original formulation, but the algorithm is quite clear: during the initialization phase, for each point not used as a centroid, calculate the distance between said point and the nearest centroid, that will be the distance D(X[i]), the pick a random point in this set of points with probability weighted with D(X[i])^2
In your formulation it seems you got m points unused.
I am not sure if the "Symmetric mean absolute surface distance" (SMAD) is used as a metric to evaluate the segmentation algorithm for 2D images or 3D images? Thanks!
What are surface Distance based metrics?
Hausdorff distance
Hausdorff distance 95% percentile
Mean (Average) surface distance
Median surface distance
Std surface distance
Note: These metrics are symmetric, which means the distance from A to B is the same as the distance from B to A.
For each contour voxel of the segmented volume (A), the Euclidean distance from the closest contour voxel of the reference volume (B) is computed and stored as list1. This computation is also performed for the contour voxels of the reference volume (B), stored as list2. list1 and list2 are merged to get list3.
Hausdorff distance is the maximum value of list3.
Hausdorff distance 95% percentile is the 95% percentile of list3.
Mean (Average) surface distance is the mean value of list3.
Median surface distance is the median value of list3.
Std surface distance is the standard deviation of list3.
References:
Heimann T, Ginneken B, Styner MA, et al. Comparison and Evaluation of Methods for Liver Segmentation From CT Datasets. IEEE Transactions on Medical Imaging. 2009;28(8):1251–1265.
Yeghiazaryan, Varduhi, and Irina D. Voiculescu. "Family of boundary overlap metrics for the evaluation of medical image segmentation." Journal of Medical Imaging 5.1 (2018): 015006.
Ruskó, László, György Bekes, and Márta Fidrich. "Automatic segmentation of the liver from multi-and single-phase contrast-enhanced CT images." Medical Image Analysis 13.6 (2009): 871-882.
How to calculate the surface distance based metrics?
seg-metrics is a simple package to compute different metrics for Medical image segmentation(images with suffix .mhd, .mha, .nii, .nii.gz or .nrrd), and write them to csv file.
I am the author of this package.
I found two papers which address the definitions of SMAD:
https://www.cs.ox.ac.uk/files/7732/CS-RR-15-08.pdf (see section 7.1 on average symmetric surface distance, but this is the same thing)
http://ai2-s2-pdfs.s3.amazonaws.com/2b8b/079f5eeb31a555f1a48db3b93cd8c73b2b0c.pdf (page 1439, see equation 7)
I tried to post the equation here but I do not have enough reputation. Basically look at equation 15 in the first reference listed above.
It appears that this is defined for 3D voxels, though I don't see why it should not work in 2D.
I read that euclidean distance is not optimal for high dimensional data, but in this publcation is written that euclidean or manhattan distance should be used.
But what better? Any benchmarks, tests?
Is it possible to obtain absolute threshhold (I know about 0.7 ratio between nearest neighbors in knn search)?
I have a Kalman filter tracking a point, with a state vector (x, y, dx/dt, dy/dt).
At a given update, I have a set of candidate points which may correspond to the tracked points. I would like to iterate through these candidates and choose the one most likely to correspond to the tracked point, but only if the probability of that point corresponding to the tracked point is greater than a threshold (e.g. p > 0.5).
Therefore I need to use the covariance and state matrices of the filter to estimate this probability. How can I do this?
Additionally, note that my state vector is four dimensions, but the measurements are in two dimensions (x, y).
When you predict the measurements with y = Hx you also compute the covariance of y as H*P*H.T. This property is why we use variance in the Kalman Filter.
The geometrical way to understand how far a given point is from your predicted point is a error ellipse or confidence region. A 95% confidence region is the ellipse scaled to 2*sigma (if that isn't intuitive, you should go read about normal distributions, because that is what the KF thinks it is working on). If the covariance is diagonal, the error ellipse will be axis aligned. If there are co-varying terms (which there may not be if you have not introduced them anywhere via Q or R) then the ellipse will be tilted.
The mathematical way is with the Mahalanobis distance, which just directly formulates the geometrical representation above as a distance. The distance scale is standard deviations, so your P=0.5 corresponds to a distance of 0.67 (again, see normal distributions if this is surprising).
The most probable point (I suppose from detections) will be the nearest point to filter prediction.
I have some problem understanding euclidean distance. I have two different entities and I want to measure the similarity between these entities.
Lets suppose that entity A has 2 feature vectors and entity B has 1 feature vector only. How am I supposed to calculate the euclidean distance between these two entities in order to know the similarity?
Thanks a lot.
you can calculate the eucledean distance only for vectors of the same dimension. But you could define some default values for the features that are missin in entity 2
L2 is between two feature vectors. These two would be natural ways of doing it:
You could find the minimum L2 distance between all the feature vectors of entity 1 and all the feature vectors of entity 2. If we have 2 vector for entity 1 like A=[1,3,2,1] and B=[3,2,4,1] AND 1 vector for entity 2 like C=[1,2,4,2]. Then dist = min(d([1,3,2,1],[1,2,4,2]),d([3,2,4,1],[1,2,4,2])
You could find the average vectors between all the vectors of entity 1 and the average vector of entity 2. Then compute the L2 distance. If we have 2 vector for entity 1 like A=[1,3,2,1] and B=[3,2,4,1] AND 1 vector for entity 2 like C=[1,2,4,2]. Then dist = d([(1+3)/2,(3+2)/2,(2+4)/2,(1+1)/2],[1,2,4,2])
This is not a bad question at all.
Sometimes mathematicians define the Euclidean distance between two sets (A and B) of elements as the minimum distance between any two pairs of elements from either set.
You can also use the maximum over these two sets. That is called the Hausdorff distance.
Distance between two sets
In other words, you can compute the Euclidean distance between each element of set A to each element of set B and then define the distance, d(A,B), between the two sets as the minimum (or maximum) distance of any of the element pairs that you've computed.
Hausdorff (maximum) distance has some nicer mathematical properties and on the space of non-empty, compact sets (which your element will be since they are discrete) it will be a proper mathematical distance, in that it satisfies:
For all non-empty compact sets A,B,C
d(A,B) >= 0 (with d(A,B) = 0 if and only if A=B)
d(A,B) = d(B,A)
d(A,B) <= d(A,C) + d(C,B)