# Solved – version of the Mahalanobis distance for matrices

I'm working on a computer vision problem and I want to use the Mahalanobis distance to cluster image patches (2D matrices having the same dimensions). I haven't been able to find any generalisation up to this point and would prefer not to vectorise my patches and end-up with a huge covariance matrix.

Since the exponent term in the multivariate Gaussian distribution density function is related to the Mahalanobis distance, I looked for a matrix version and I found the Matrix normal distribution:

The probability density function for the random matrix \$mathbf{X}(ntimes p)\$ that follows the matrix normal distribution \$mathcal{MN}_{n,p}(mathbf{M}, mathbf{U}, mathbf{V})\$ has the form:

\$p(mathbf{X}midmathbf{M}, mathbf{U}, mathbf{V}) = frac{expleft( -frac{1}{2} , mathrm{tr}left[ mathbf{V}^{-1} (mathbf{X} – mathbf{M})^{T} mathbf{U}^{-1} (mathbf{X} – mathbf{M}) right] right)}{(2pi)^{np/2} |mathbf{V}|^{n/2} |mathbf{U}|^{p/2}}
\$

where \$mathrm{tr}\$ denotes trace and \$mathbf{M}\$ is \$ntimes p\$, \$mathbf{U}\$ is \$ntimes n\$ and \$mathbf{V}\$ is \$ptimes p\$.

Now, my question is : is the trace term a generalisation of the Mahalanobis distance applied on matrices or is there another formulation ?

Contents