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 = 
    ImagePad[original, {{30, -30}, {5, -5}}, 
     Padding -> "Reflected"]];

twin mandrills

and ran a set of ImageDistance operations past them:

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

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

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


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

  • $\begingroup$ Not sure whether this question is entirely suitable for here, so I wouldn't mind too much if it were closed... :) $\endgroup$
    – cormullion
    Dec 7, 2012 at 12:36
  • $\begingroup$ How is it not suitable? $\endgroup$
    – Mr.Wizard
    Dec 7, 2012 at 12:40
  • $\begingroup$ 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. $\endgroup$
    – cormullion
    Dec 7, 2012 at 12:44
  • $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Dec 7, 2012 at 16:23

2 Answers 2


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

  • $\begingroup$ 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... $\endgroup$
    – cormullion
    Dec 7, 2012 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.

  • 1
    $\begingroup$ Yes, I've found some useful introductory references in - cough - Matlab's documentation... $\endgroup$
    – cormullion
    Dec 10, 2012 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.