standardised Distance interface (Feature #2308)


Added by Hilton Bristow over 12 years ago. Updated over 9 years ago.


Status:Open Start date:2012-08-26
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:3.0
Difficulty: Pull request:

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.


distance.hpp (3.8 kB) Hilton Bristow, 2012-08-26 08:53 am


Associated revisions

Revision 63dbe66b
Added by Roman Donchenko about 11 years ago

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

Also available in: Atom PDF