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

6 views (last 30 days)

Show older comments

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

##### 1 Comment

Alvindra Pratama
on 24 May 2016

### Answers (2)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!