# How is that distance between images calculated?

The command

ImageDistance[Plot[x^2, {x, 0, 1}, PlotRange -> {0, 1.01}],
Plot[x^2 + 0.01, {x, 0, 1}, PlotRange -> {0, 1.01}]]


produces 33.3253. Unfortunately, the Mathematica help to ImageDistance says nothing how the distance is calculated. The images are very similar.

• The documentation for ImageDistance's "Details and Options" says that EuclideanDistance is the default. You can give a different DistanceFunction as an option. – Carl Lange Mar 6 at 17:08
• Yes, but what is it? Which formulas are applied to this end? – user64494 Mar 6 at 17:09
• @user64494 I cast a downvote because, in my opinion, yours is not a question, but an observation. I am not sure what you would consider an acceptable answer, short of providing documentation that is currently not available to us. Perhaps it would be more useful to bring this issue up with Wolfram Support, if your goal is to have better documentation. Additionally, this may turn out to be an XY problem, i.e. you are asking about your perceived solution of a problem, rather than about the issue itself that you are having. – MarcoB Mar 6 at 19:03
• @MarkoB: My question was inspired by a too poor Mathematica documentation to ImageDistance, where I didn't find an answer. I followed your advice concerning Wolfram Support. – user64494 Mar 6 at 19:13
• If your arguments are Graphics, then I believe ImageDistance is doing the following: id[i1_,i2_]:=EuclideanDistance[ Flatten @ ImageData @RemoveAlphaChannel[Image[i1],Black], Flatten @ ImageData @RemoveAlphaChannel[Image[i2],Black] ] – chuy Mar 6 at 19:26

## 1 Answer

The documentation for ImageDistance's "Details and Options" says that EuclideanDistance is the default. You can give a different DistanceFunction as an option.

You can replicate what ImageDistance is doing by default like so:

i1 = Rasterize@Plot[x^2, {x, 0, 1}, PlotRange -> {0, 1.01}];
i2 = Rasterize@Plot[x^2 + 0.01, {x, 0, 1}, PlotRange -> {0, 1.01}];


Then,

ImageDistance[i1, i2]


25.6833

EuclideanDistance[Flatten@ImageData@i1, Flatten@ImageData@i2]


25.6833

We can do the same with other distance functions, for example:

ImageDistance[i1, i2, DistanceFunction -> CorrelationDistance]


0.245972

CorrelationDistance[Flatten@ImageData@i1, Flatten@ImageData@i2]


0.245972