# how to use mahalanobis.m to calculate mahalanobis distance of an image

64 views (last 30 days)
junfei li on 24 Apr 2016
Edited: Image Analyst on 8 Sep 2018
I have a homework ask me using mahalanobis.m to calculate the mahalanobis distance of a color in an image. themahalanobis.m comes from DIPUM(gonzalez), it is easy to find on google.
the homework is i have a color and know its rgb(like: [150 97 210]), now i need to calculate its mahalanobis distance of a rgb image. the professor give us a matlab function: mahalanobis.m and this is part of the code and easy to find on google.
function d = mahalanobis(varargin)
% MAHALANOBIS Computes the Mahalanobis distance.
% D = MAHALANOBIS(Y, X) computes the Mahalanobis distance between
% each vector in Y to the mean (centroid) of the vectors in X, and
% outputs the result in vector D, whose length is size(Y, 1). The
% vectors in X and Y are assumed to be organized as rows. The
% input data can be real or complex. The outputs are real
% quantities.
%
% D = MAHALANOBIS(Y, CX, MX) computes the Mahalanobis distance
% between each vector in Y and the given mean vector, MX. The
% results are output in vector D, whose length is size(Y, 1). The
% vectors in Y are assumed to be organized as the rows of this
% array. The input data can be real or complex. The outputs are
% real quantities. In addition to the mean vector MX, the
% covariance matrix CX of a population of vectors X also must be
% provided. Use function COVMATRIX (Section 11.5) to compute MX and
% CX.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% \$Revision: 1.6 \$ \$Date: 2005/01/18 13:44:47 \$
the problem is I don't know how to use this function. I don't know what is X and Y, how to use my image and the color to find X and Y
Alvindra Pratama on 24 May 2016
are you have found the solution of the problem? because I also have the same problem with yyou, so I also needed a solution too, please help me

Arnab Sen on 28 Apr 2016

AJITH B on 8 Sep 2018
Edited: Image Analyst on 8 Sep 2018