Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mahalanobis distance in Kmeans Clustering using OpenCV

I have done Kmeans clustering and found out the Cluster centers using OpenCV C++ API.

kmeans(data_points, clusterCount, labels, TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0), 3, KMEANS_PP_CENTERS, cluster_centers);

Then I'm using euclidean distance to find closest cluster for a new data point against all cluster centers.

int distance = find_EucledianDist(new_datapoint, cluster_centers);

How would I use Mahalanobis Distance instead of Euclidean Distance? I know I have to calculate Covariance Matrix and Invert it and find Mahalanobis Distance.

However, I don't know how I do that and in what ORDER (find covar matrix, inverted matrix of which data/matrix)?

like image 447
garak Avatar asked Feb 28 '12 13:02

garak


1 Answers

Can't this link help you a lot? :)

http://books.google.fr/books?id=seAgiOfu2EIC&pg=PA475&lpg=PA475&dq=mahalanobis+opencv&source=bl&ots=hSG09ijHLe&sig=H359_fRI53Pg12dYLOVUJpopb0g&hl=fr&sa=X&ei=O-JMT9-oAYem0AXIpL2eBQ&ved=0CEkQ6AEwBA#v=onepage&q=mahalanobis%20opencv&f=false

This would be : CalcCovarMatrix, followed by cvInvert, and finally cvMahalanobis.

like image 86
jlengrand Avatar answered Sep 28 '22 08:09

jlengrand