ImageMagick比较:忽略PSNR结果中的白色匹配 [英] ImageMagick compare: Disregard white matches from the PSNR result

查看:216
本文介绍了ImageMagick比较:忽略PSNR结果中的白色匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 比较 来区分两个类似的颜色 PNG文件。他们获得的 PSNR 值为~27。

I'm using compare to diff two similar color PNG files. They get a PSNR value of ~27.

图像包含许多白色区域,这两个区域在两个图像之间始终匹配。如果我错了,请纠正我,但这些白色区域正在增加PSNR值(使图像与平均值更相似)。因此,我不想考虑白色像素, IF 匹配。

The images contain a lot of white areas that will always match between the two images. Correct me if i'm wrong, but these white areas are increasing the PSNR values (making the images more similar as an average). Therefore I don't want to take white pixels into account, IF they match.

有没有办法使用比较或通过考虑其他一些工具来做到这一点?

Is there a way to do this using compare or by factoring in some other tool?

我试过设置 -transparent-color 为白色,但这没有效果。

I tried setting -transparent-color to white, but this had no effect.

这是我的命令:

compare -compose src -metric PSNR img1.png img2.png diff.png

编辑:

compare --version
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org

convert --version
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org

我想忽略白色像素可能是垃圾,但我仍然希望实现更好的比较。

My idea about ignoring white pixels may be rubbish, but I still want to achieve a better comparison.

澄清:

想象一下这种情况:你比较两个图像,它们不同一点点。然后,为这些图像添加一个大的白色边框。你再次差异,发现所得的PSNR值已经上升了一些。我想要的是一种否定这一点的方法。显然两个图像中的白色边框都是相同的...

To clarify:
Imagine this situation: you compare two images, they differ a bit. You then add a big white border to those images. You diff again and find that the resultant PSNR value has risen some amount. What I want is a way to negate this. Obviously the white borders are the same in both images...

推荐答案

像Mark Setchell一样,我并不完全明白你的真实情况意图是。您不提供任何(链接)样本图像,这可能有助于我们掌握您的最新动态。

Like Mark Setchell, I do not fully understand what your real intention is. You do not provide any (links to) sample images which may help us to grasp what you are up to.

这就是我自己创建4个样本图像的原因。这是第一对:

That's why I created 4 sample images myself. Here is the first pair:


  • 左边是JPEG。

  • 正确的是PNG。

差异极小 - 在这里复制时,你几乎无法用肉眼发现它们。两张图片均为482x642像素:

Differences are minimal -- you'll hardly be able to spot them with the naked eye when reproduced here. Both images are 482x642 pixels:

 

这是第二对。再次,


  • 左边是JPEG;

  • 右边是PNG。

通过在初始对周围添加白框,这些都被放大到1002x1002像素。在下面的复制中,由于此网页内的缩放比例不同,它们看起来更小:

These are both enlarged to 1002x1002 pixels by adding a white frame around the initial pair. In the following reproduction they appear smaller because of the different scaling inside this web page:

 

所以第二对的重要部分是黑框中包含的部分。外边界上的白框是相同的。

So the "important" parts of the second pair are what is contained in the black frames. The white frames on the outer bound is identical.

现在让我们比较两对。但我不想将比较仅限于PSNR指标。我想查看所有可用的指标。我们可以使用以下命令列出可用的指标:

Now lets compare both pairs. But I do not want to limit the comparisons to just the PSNR metric. I want to see all available metrics. We can list available metrics with this command:

compare -list metric
 AE
 Fuzz
 MAE
 MEPP
 MSE
 NCC
 PAE
 PHASH
 PSNR
 RMSE

我返回第一个对的指标的命令是:

My command to return the metrics for the first pair is this:

for metric in $(compare -list metric) ; do  \
   echo -n "Metric ${metric} :  " ;         \
   compare                                  \
      -metric ${metric}                     \
       http://i.stack.imgur.com/TEjAd.jpg   \
       http://i.stack.imgur.com/p8JsE.png   \
       null: ;                              \
   echo ;                                   \
done

这是第一对的结果(略微重新格式化) (仅重要部分):

Here is the result (slightly re-formatted) for the first pair ("important" part only):

Metric AE    :  123789
Metric Fuzz  :     948.522      (0.0144735)
Metric MAE   :     381.318      (0.00581854)
Metric MEPP  :       3.5399e+08 (0.000209349, 0.32549)
Metric MSE   :      13.7285     (0.000209483)
Metric NCC   :       0.998307
Metric PAE   :   21331          (0.32549)
Metric PHASH :       5.43771
Metric PSNR  :      36.7885
Metric RMSE  :     948.522      (0.0144735)

我返回第二个对的指标的命令是:

My command to return the metrics for the second pair is this:

for metric in $(compare -list metric) ; do  \
   echo -n "Metric ${metric} :  " ;         \
   compare                                  \
      -metric ${metric}                     \
       http://i.stack.imgur.com/gBruS.jpg   \
       http://i.stack.imgur.com/8NJeB.png   \
       null: ;                              \
   echo ;                                   \
done

这是第二对的结果(略微重新格式化) (通过添加大量白框来淡化差异):

Here is the result (slightly re-formatted) for the second pair ("watered down" differences by added massive white frame):

Metric AE    :  133609
Metric Fuzz  :     611.952       (0.00933779)
Metric MAE   :     143.849       (0.00219499)
Metric MEPP  :       4.33273e+08 (8.71895e-05, 0.341176)
Metric MSE   :       5.71428     (8.71944e-05)
Metric NCC   :       0.998137
Metric PAE   :   22359           (0.341176)
Metric PHASH :       0.360076
Metric PSNR  :      40.5951
Metric RMSE  :     611.952       (0.00933779)

这两个结果都在一个公用表中:

Here are both results in a common table:

+==============+=======================================+=========================================+
| Metric Type  | Results for "important" image parts   | Results including "unimportant" frames  |
+==============+=======================================+=========================================+
| Metric AE    | 123789                                | 133609                                  |
| Metric Fuzz  |    948.522      (0.0144735)           |    611.952       (0.00933779)           |
| Metric MAE   |    381.318      (0.00581854)          |    143.849       (0.00219499)           |
| Metric MEPP  |      3.5399e+08 (0.000209349, 0.32549)|      4.33273e+08 (8.71895e-05, 0.341176)|
| Metric MSE   |     13.7285     (0.000209483)         |      5.71428     (8.71944e-05)          |
| Metric NCC   |      0.998307                         |      0.998137                           |
| Metric PAE   |  21331          (0.32549)             |  22359           (0.341176)             |
| Metric PHASH |      5.43771                          |      0.360076                           |
| Metric PSNR  |     36.7885                           |     40.5951                             |
| Metric RMSE  |    948.522      (0.0144735)           |    611.952       (0.00933779)           |
+==============+========================================+=========================================+

注意: 将两个相同的图像与PSNR指标进行比较将得出 inf (无限期)值。

Note: comparing two identical images with the PSNR metric would result in an inf (infinitiv) value.

现在得出你自己的结论......

Now draw your own conclusions...

了解比较指标不是一件简单的事情。

Understanding comparison metrics is not a straight forward affair.

您对PSNR的理解似乎有点偏离我的解释编辑:

Your own understanding of the PSNR seems to be a bit off, from how I interpret your ''


澄清:

想象一下这种情况:你比较两个图像,他们有点不同。然后,为这些图像添加一个大的白色边框。你再次差异,发现结果的PSNR值已经上升了一些。

To clarify:
Imagine this situation: you compare two images, they differ a bit. You then add a big white border to those images. You diff again and find that the resultant PSNR value has risen some amount.

因为上升值为PSNR意味着两个比较的图像彼此变得更加相同! (当然,您打算在比较它们之前删除图像周围的白色(或其他颜色)框架/边框仍然是一种合理的方法。要了解如何做到这一点,请查看我的答案的结尾。 ..)

Because a rising value for PSNR means that the two compared images have become a bit more identical to each other! (Of course, your intention to remove white (or otherwise colored) frames/borders around images before comparing them is still a reasonable approach. To see how to do that, look at the end of my answer...)

为了更好地了解图像比较指标,您应首先创建一些简单的图像。然后开始尝试这些。

In order to get a better feeling for image comparison metrics, you should create a few simple "images" first. Then start experimenting with these.

这是一个建议如何创建一系列单色补丁,每个大小为100x100像素:

Here is a suggestion how to create a series of mono-colored "patches", sized 100x100 pixels each:

for col in black white blue green red; do               \
  convert -size 100x100 xc:${col} xc-100px-${col}.png ; \
done

       

    

实验任务: 将每个100x100像素的补丁相互比较。

问题:

Experimental Task: Compare each of the 100x100 pixels patches against each other.
Questions:


  • 如果您将黑白指标与黑蓝或红绿指标并列,那么值得注意的是什么?

  • 你有意外的结果吗?为什么这样?

现在对200x200像素的补丁做同样的事情:

Now do the same for patches with 200x200 pixels:

for col in black white blue green red; do               \
  convert -size 200x200 xc:${col} xc-200px-${col}.png ; \
done

实验任务: 将每个200x200像素的补丁相互比较。

问题:

Experimental Task: Compare each of the 200x200 pixels patches against each other.
Questions:


  • 200x200图像的相应color1-color2指标是否偏离100x100图像的相同color1-color2指标?

  • 是否有一些指标将相同的结果返回到各自的对应部分?为什么这样?

现在在每个100x100像素补丁周围添加一个50像素宽的红框。生成的图像的大小也将为200x200像素:

Now add a 50 pixels wide red frame around each of the 100x100 pixel patches. The resulting images will also be of size 200x200 pixels:

for img in xc-100px-*.png ; do \
   convert                     \
     ${img}                    \
    -mattecolor red            \
    -frame 50x50               \
     redframed-${img} ;        \
done

实验任务: 组成自己的比较对。 (你知道也可以比较200x200像素'单色'补丁与200x200像素'红框'补丁...)

b $ b 问题:

Experimental Task: Make up your own comparison pairs. (You know can also compare 200x200 pixel 'mono-color' patches against 200x200 pixels 'redframed' patches...)
Questions:


  • 哪些是合理的比较?

  • 您是否知道 -metric phash 是唯一允许您使用不同尺寸(宽x高)比较图像的方式?

  • Which are reasonable comparisons?
  • Did you know that the -metric phash is the only one which allows you to compare images using different dimensions (width x height) ?

你可以删除任何'框架'围绕由相同颜色的像素组成的图像。图像操作符 -trim 将自动为您实现此目的。 (它适用于不同于白色的颜色。)

You can remove any 'frame' around an image that is composed of identically colored pixels. The image operator -trim will achieve this automatically for you. (It works for colors different than white too.)

convert reframed-xc-100px-blue.png -trim +repage output.png

identify redframed-xc-100px-blue.png  output.png
 redframed-xc-100px-blue.png PNG 200x200 200x200+0+0 8-bit sRGB 3c 322B 0.000u 0:00.000
               output.png[1] PNG 100x100 100x100+0+0 8-bit sRGB 2c 285B 0.000u 0:00.000

 

这篇关于ImageMagick比较:忽略PSNR结果中的白色匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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