【问题标题】:Compare rendered images using imagemagick使用 imagemagick 比较渲染图像
【发布时间】:2016-08-06 04:46:58
【问题描述】:

我已经从一个应用程序渲染了多个图像。以下示例图片展示了两幅看起来几乎相同的图片。

我尝试将它们与 image magick 中的以下命令进行比较。

compare -metric AE img1.png img2.png diff.png
6384

这意味着即使图像相似,也有 6384 像素不同。

我得到了一些细微的变化,比如如果将图案向右移动 1 个像素,这会给我在不同像素数量上带来很大的错误。有没有用 ImageMagick 做这种差异的好方法?我已经尝试过 fuzz 参数,但它确实对我没有帮助。 ImageMagick compare 是否仅适用于比较照片图像?是否有更好的 ImageMagick 开关可以识别移动了一些像素的文本并将其报告为相等?我应该使用其他工具吗?

编辑: 在图像上添加一个对人类来说看起来明显不同的示例,并将说明我试图区分的差异类型。在这张图片中,没有多少像素发生变化,但可见的图案发生了明显的变化。

【问题讨论】:

  • 您希望发现或期望发现什么样的差异?
  • 添加了一个与人类不同的图像示例。

标签: unit-testing image-processing graphics imagemagick diff


【解决方案1】:

很难给出任何详细的答案,因为我不知道您在寻找或期待什么。如果您正在寻找人们认为相似或不相似的图像,我想您可能需要某种 Perceptual Hash,或者可能需要一种 Scale/Rotation/Translation Invariant 技术独立于调整大小、移位和旋转来识别相似图像。

您可以像这样使用 ImageMagick 查看 Perceptual Hash 和 Image Moments:

identify -verbose -features 1 -moments 1.png
Image: 1.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: PseudoClass
  Geometry: 103x115+0+0
  Resolution: 37.79x37.79
  Print size: 2.72559x3.04313
  Units: PixelsPerCentimeter
  Type: Grayscale
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 8-bit
  Channel statistics:
    Pixels: 11845
    Gray:
      min: 62 (0.243137)
      max: 255 (1)
      mean: 202.99 (0.79604)
      standard deviation: 85.6322 (0.335812)
      kurtosis: -0.920271
      skewness: -1.0391
      entropy: 0.840719
  Channel moments:
    Gray:
      Centroid: 51.6405,57.1281
      Ellipse Semi-Major/Minor axis: 66.5375,60.336
      Ellipse angle: 0.117192
      Ellipse eccentricity: 0.305293
      Ellipse intensity: 190.641 (0.747614)
      I1: 0.000838838 (0.213904)
      I2: 6.69266e-09 (0.00043519)
      I3: 3.34956e-15 (5.55403e-08)
      I4: 5.38335e-15 (8.92633e-08)
      I5: 2.27572e-29 (6.25692e-15)
      I6: -4.33202e-19 (-1.83169e-09)
      I7: -2.16323e-30 (-5.94763e-16)
      I8: 3.96612e-20 (1.67698e-10)
  Channel perceptual hash:
    Red, Hue:
      PH1: 0.669868, 11
      PH2: 3.35965, 11
      PH3: 7.27735, 11
      PH4: 7.05343, 11
      PH5: 11, 11
      PH6: 8.746, 11
      PH7: 11, 11
    Green, Chroma:
      PH1: 0.669868, 11
      PH2: 3.35965, 11
      PH3: 7.27735, 11
      PH4: 7.05343, 11
      PH5: 11, 11
      PH6: 8.746, 11
      PH7: 11, 11
    Blue, Luma:
      PH1: 0.669868, 0.669868
      PH2: 3.35965, 3.35965
      PH3: 7.27735, 7.27735
      PH4: 7.05343, 7.05343
      PH5: 11, 11
      PH6: 8.746, 8.746
      PH7: 11, 11
  Channel features (horizontal, vertical, left and right diagonals, average):
    Gray:
      Angular Second Moment:
        0.364846, 0.615673, 0.372224, 0.372224, 0.431242
      Contrast:
        0.544246, 0.0023846, 0.546612, 0.546612, 0.409963
      Correlation:
        -0.406263, 0.993832, -0.439964, -0.439964, -0.07309
      Sum of Squares Variance:
        1.19418, 1.1939, 1.19101, 1.19101, 1.19253
      Inverse Difference Moment:
        0.737681, 1.00758, 0.745356, 0.745356, 0.808993
      Sum Average:
        1.63274, 0.546074, 1.63983, 1.63983, 1.36462
      Sum Variance:
        4.43991, 0.938019, 4.46048, 4.46048, 3.57472
      Sum Entropy:
        0.143792, 0.159713, 0.143388, 0.143388, 0.14757
      Entropy:
        0.462204, 0.258129, 0.461828, 0.461828, 0.410997
      Difference Variance:
        0.0645055, 0.189604, 0.0655494, 0.0655494, 0.0963021
      Difference Entropy:
        0.29837, 0.003471, 0.297282, 0.297282, 0.224101
      Information Measure of Correlation 1:
        -0.160631, -0.971422, -0.146024, -0.146024, -0.356026
      Information Measure of Correlation 2:
        0.294281, 0.625514, 0.29546, 0.29546, 0.377679

您也可以访问 Fred Weinhaus 的优秀网站 (here) 并下载名为 moments 的脚本,该脚本将计算 Hu 和 Maitra 时刻,看看是否能告诉您您想要什么。基本上,您可以像这样在每个图像上运行脚本:

./moments image1.png > 1.txt
./moments image2.png > 2.txt

然后使用您最喜欢的diff 工具查看您希望比较的两张图片之间的变化。

【讨论】:

    猜你喜欢
    • 2013-12-30
    • 2017-03-14
    • 2015-11-01
    • 1970-01-01
    • 2019-10-11
    • 2015-02-01
    • 1970-01-01
    • 2015-06-28
    • 2015-09-27
    相关资源
    最近更新 更多