Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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[
    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", 
   "MeanSquaredEuclideanDistance", 
   "MeanReciprocalSquaredEuclideanDistance",
   {"MeanReciprocalSquaredEuclideanDistance", .3}, 
   "MutualInformationVariation", {"MutualInformationVariation", 32}, 
   "NormalizedMutualInformationVariation",
   {"NormalizedMutualInformationVariation", 32}, 
   "DifferenceNormalizedEntropy", {"DifferenceNormalizedEntropy", 32},
   "MeanPatternIntensity", {"MeanPatternIntensity", .1, 3}, 
   "GradientCorrelation", "MeanReciprocalGradientDistance", 
   "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, "."}}]

results

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

share|improve this question
    
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
add comment

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

share|improve this answer
    
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
add comment

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.

share|improve this answer
1  
Yes, I've found some useful introductory references in - cough - Matlab's documentation... –  cormullion Dec 10 '12 at 8:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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