# What is ImageDistance measuring?

What quantity is ImageDistance measuring, and what do the numbers mean?

I found the ImageDistance command in Mathematica 9, but I've been unable to find much explanation about what it's doing. I originally thought it might be calculating the distance between features on images, but I don't think it is any more.

I created two images that had some obvious differences:

original = ExampleData[{"TestImage", "Mandrill"}];
shiftedImage =
Sharpen[


and ran a set of ImageDistance operations past them:

flist = {EuclideanDistance, SquaredEuclideanDistance,
NormalizedSquaredEuclideanDistance, ManhattanDistance,
CosineDistance, CorrelationDistance, "MeanEuclideanDistance",
"MeanSquaredEuclideanDistance",
"MeanReciprocalSquaredEuclideanDistance",
{"MeanReciprocalSquaredEuclideanDistance", .3},
"MutualInformationVariation", {"MutualInformationVariation", 32},
"NormalizedMutualInformationVariation",
{"NormalizedMutualInformationVariation", 32},
"DifferenceNormalizedEntropy", {"DifferenceNormalizedEntropy", 32},
"MeanPatternIntensity", {"MeanPatternIntensity", .1, 3},
"EarthMoverDistance", {"EarthMoverDistance", 4}};

results = Sort[
Table[
{f, ImageDistance[original, shiftedImage,
DistanceFunction -> f]}, {f, flist}],
#1[[2]] > #2[[2]] &];

Grid[
Table[
{First[row], PaddedForm[ Last[row], {Automatic, 6}]}, {row,
results}],
Alignment -> {{Left, "."}}]


Trying different pairs of images hasn't helped, yet. Can anyone enlighten me (in novice-friendly terms)?

-
Not sure whether this question is entirely suitable for here, so I wouldn't mind too much if it were closed... :) –  cormullion Dec 7 '12 at 12:36
How is it not suitable? –  Mr.Wizard Dec 7 '12 at 12:40
Perhaps I was hoping for 'extended discussion' ... :) I suppose I'm looking for explanations rather than answers, although I tried to phrase it in an answerable way. –  cormullion Dec 7 '12 at 12:44
Why not try passing ImageDistance the distance function (Print[{#1, #2]; 0)& to see what you get? I'd use small images to test this to keep down the amount printed. –  m_goldberg Dec 7 '12 at 16:23

I'm not sure if that answers your question: It seems to compare the two images pixel by pixel, i.e. pixel (1,1) from image A is compared to pixel (1,1) from image B. No alignment or registration is performed, so the result is not a geometrical distance in pixels, but rather a measure for intensity/color difference. Or, put another way: ImageDistance seems to treat both images as flat vectors:

In[5]:= EuclideanDistance[Flatten[ImageData[original]], Flatten[ImageData[shiftedImage]]]

Out[5]= 268.341


returns the same value as ImageDistance[..., DistanceFunction -> EuclideanDistance].

If you want a geometric distance based on keypoints, FindGeometricTransform is probably more helpful.

For example:

transform = Last@FindGeometricTransform[original, shiftedImage];
Norm[transform[{0, 0}]]

=> 30.6124


which is close to the the ideal Norm[{30., 5.}] = 30.4138

-
The distance between pixels should be 35.3553, though, if it was measuring 'pixel-to-pixel distance'. Which is why I thought it was measuring something entirely different... Perhaps I should have asked what 'pixel-to-pixel distance' means... –  cormullion Dec 7 '12 at 13:19

There are many ways to characterize the "difference" ( aka "distance") between a pair of images, the choice of which comes down to what you're trying to measure. You might, for example want to find the best alignment between two images, or maybe you want to search for images that share similar color distributions. MMA gives you quite a few common distance measures, and they're all briefly documented, but to learn more, find some good image processing textbooks.

-
Yes, I've found some useful introductory references in - cough - Matlab's documentation... –  cormullion Dec 10 '12 at 8:48