Reputation: 183
I don't understand how the compare
script of imagequick work.
I compare an image to the same image (a copy)
I do
compare -metric A.png B.png C.png
B.png
is exactly the same image as A.png
(I did a copy)
Here is the result.
I was thinking that C.png
will be fully white, but that is not.
I would like to know if two image are stricly identic. Is it possible to get an ouput which will tell me "yes, the two images are identic" or "no, the two images are note identic".
Upvotes: 0
Views: 651
Reputation: 207425
Here are some examples to help you understand how image comparison works.
The -metric AE
tells you the Absolute Error, which is the number of pixels that differ - so it will be zero if all pixels are identical.
1. Compare two images that are exact copies of each other in every respect
convert -size 128x128 xc:red red.png # Make red image
cp red.png perfectCopy.png # Make perfect copy
compare -metric AE red.png perfectCopy.png result.png # Count differing pixels
0 # There are none - identical
According to standard Unix tools (md5
, diff
, tmp
), files are binary identical and md5 checksums identical:
md5 red.png perfectCopy.png
MD5 (red.png) = 39236e0e0dfb70da0e9bcbfbcf7b8181
MD5 (perfectCopy.png) = 39236e0e0dfb70da0e9bcbfbcf7b8181
ImageMagick hashes over pixels only (not including metadata) are identical:
identify -format "%#:%f\n" red.gif perfectCopy.png
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:red.gif
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:perfectCopy.png
2. Compare two images with identical appearance but different metadata
convert -size 128x128 xc:red red.png # Make red image
sleep 2
convert -size 128x128 xc:red redDifferentDate.png # Make red image with different date
compare -metric AE red.png redDifferentDate.png result.png
0 # No difference
But, according to standard Unix tools (diff
,md5
,sum
), the files are different - because the date is in there.
md5 red.png redDifferentDate.png
MD5 (red.png) = 004088f6d275f431cedb74bc0209bbc5
MD5 (redDifferentDate.png) = d7d36f56e1940251f9804bd795ef4157
But ImageMagick knows images better, and its calculated hashes (checksum) over pixel data only (not including metadata) are the same:
identify -format "%#:%f\n" red.gif redDifferentDate.png
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:red.gif
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:redDifferentDate.png
3. Compare two images with identical pixels, but totally different sizes and formats
convert -size 128x128 xc:red red.png # Make red PNG
convert -size 128x128 xc:red red.gif # Make red GIF
compare -metric AE red.png red.gif result.png # Count differing pixels
0 # No difference
But, files and md5 hashes differ:
diff red.png red.gif
Binary files red.png and red.gif differ
md5 red.png red.gif
MD5 (red.png) = aed0840c2c99425c25bd782e7b409022
MD5 (red.gif) = 5869df00d7b3cab3495a6c402ba61ec9
Again, ImageMagick knows better and the hashes over pixel data only (not including metadata) are still the same:
identify -format "%#:%f\n" red.gif red.png
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:red.gif
1157038985fec4573888bc7e74a5a728e3aa5cbc49e18253c934295162a9aeea:red.png
4. Compare two grossly different files
Obviously if we create two grossly different files each full of random noise, everyone agrees they are different:
convert -size 128x128 xc:gray +noise random random1.png # Make random image
convert -size 128x128 xc:gray +noise random random2.png # Make random image
compare -metric AE random[12].png result.png # Count differing pixels
16384 # Yep, a fair few differ!
There are other metrics available, such as MeanSquared, RootMeanSquared etc - you can list them using:
identify -list metric
Output
AE
Fuzz
MAE
MEPP
MSE
NCC
PAE
PHASH
PSNR
RMSE
Upvotes: 3