standardised Distance interface (Feature #2308)
Description
I would like to propose a standardized interface for distance functions in OpenCV. I have outlined one such interface in the attached file. I have implemented a simple Euclidean distance function as an example, but if you like the interface I can implement Mahalanobis, Manhattan, Cosine, Correlation, etc.
Aspects of the interface that I deem important:- standardized. If functions require a DistanceFunction functor, then we can pass any subclass and expect it to work.
- speed. Obvious.
- can maintain state. Say you want a euclidean distance that is only based upon the k-nearest neighbours and zero elsewhere. As long as the distance function is aware of the neighbourliness, this detail can remain transparent to the actual calling function.
- generalize to any dimensionality. Computer vision is no longer about just images. We should not restrict users to find the euclidean distance between 2D points.
For example, finding the pairwise distance between a set of datapoints (pdist() in matlab) is as simple as:
int M, K; // M datapoints, K dimensions Mat_<float> data(M, K); Mat_<float> pairwise(M, M); randn(data, 1, 1); EuclideanDistance<float> distance(K); for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { pairwise(i,j) = distance(data[i], data[j]); } }
This would go a long way to producing more general algorithms such as K-dimensional kmeans(), or keypoint matching using complex distance metrics.
Associated revisions
Merge pull request #2308 from jet47:gpu-tests-timeout
History
Updated by Kirill Kornyakov over 12 years ago
- Category set to core
Updated by Alexander Smorkalov over 12 years ago
- Assignee set to Vadim Pisarevsky
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4418