使用imagequick比较图像 [英] Use imagequick to compare images

查看:44
本文介绍了使用imagequick比较图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白imagequick的 compare 脚本如何工作.

I don't understand how the compare script of imagequick work.

我将图像与相同图像(副本)进行比较

I compare an image to the same image (a copy)

我愿意

<代码>比较-metric A.png B.png C.png

B.png A.png 完全相同(我做了一个副本)

B.png is exactly the same image as A.png (I did a copy)

这是结果.

我本以为 C.png 将是全白的,但事实并非如此.

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".

推荐答案

以下是一些示例,可帮助您了解图像比较的工作原理.

Here are some examples to help you understand how image comparison works.

-metric AE 告诉您 Absolute Error ,它是不同像素的数量-因此,如果所有像素都相同,它将为零.

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.比较每张彼此完全完全相同的两张图像

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

根据标准Unix工具( md5 diff tmp ),文件是二进制相同的,而md5校验和相同:

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 仅像素上的散列(不包括元数据)是相同的:

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.比较外观相同但元数据不同的两张图片

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

但是,根据标准Unix工具( diff md5 sum ),文件是不同的-因为日期在那里

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

但是 ImageMagick 更了解图像,并且其仅针对像素数据(不包括元数据)计算出的哈希值(校验和)是相同的:

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.比较两个像素相同但大小和格式完全不同的图像

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

但是,文件和md5哈希不同:

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

同样, ImageMagick 知道的更好,并且仅像素数据(不包括元数据)的哈希值仍然相同:

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.比较两个完全不同的文件

很明显,如果我们创建两个完全不同的文件,每个文件都充满随机噪声,那么每个人都同意它们是不同的:

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!


还有其他可用指标,例如 MeanSquared RootMeanSquared 等-您可以使用以下方法列出它们:


There are other metrics available, such as MeanSquared, RootMeanSquared etc - you can list them using:

identify -list metric

输出

AE
Fuzz
MAE
MEPP
MSE
NCC
PAE
PHASH
PSNR
RMSE

这篇关于使用imagequick比较图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆