blackswan wrote:Thank you for your answer. It's not what I'm looking for, unfortunately.
I should explain why I need that operation.
It's a kind of a 3-axis distance function for a RGB difference of two images,
distance = sqrt(r**2 + g**2 +b**2)
it allows to turn RGB difference to a better grayscale one, than allowed by standard operators, I think
That is exactly what I coded above, except it is the rms distance. The m means mean. You cannot add 3 values that range 0-255 (0-65535) in IM because it will produce a value larger than 255. Thus things will be clamped at white because IM is compiled as integer unless you compile in HDRI.
so the correct rms distance is
distance = sqrt((r**2 + g**2 +b**2)/3)
If you are on Windows then the syntax is slightly different. Remove the \ and replace the \ at the end of the lines with ^.
See
http://www.imagemagick.org/Usage/windows/
which works fine for my images with the code above.
The difference between your result and mine will simply be a factor of sqrt(3). But than puts your result beyond 255 by sqrt(3) and it will be clipped to 255.
Do you really mean that you want:
distance = sqrt(((r1-r2)**2 + (g1-g2)**2 + (b1-b2)**2)/3)
where you have two images: image1 and image2? If so, you can do:
convert image1 image2 -compose difference -composite \
-set colorspace RGB -separate +channel \
\( -clone 0 -clone 0 -compose multiply -composite \) \
\( -clone 1 -clone 1 -compose multiply -composite \) \
\( -clone 2 -clone 2 -compose multiply -composite \) \
-delete 0-2 -evaluate-sequence
mean \
-evaluate pow 0.5 \
result1.png
convert image1 image2 -compose difference -composite \
-set colorspace RGB -separate +channel \
\( -clone 0 -clone 0 -compose multiply -composite \) \
\( -clone 1 -clone 1 -compose multiply -composite \) \
\( -clone 2 -clone 2 -compose multiply -composite \) \
-delete 0-2 -evaluate-sequence
add \
-evaluate pow 0.5 \
result2.png
However, the latter may overflow white and get clipped at white
see
http://www.imagemagick.org/Usage/compare/#difference
also
http://www.imagemagick.org/Usage/compare/#compare
http://www.imagemagick.org/Usage/compare/#statistics (-metric rmse)