0
votes

I have rendered multiple images from an application. Here is sample images that illustrate two images that looks almost the same to the eye .

img1 img2

I try to compare them with the following command in image magick.

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

This means 6384 pixels differ even if the images are similar.

I got minor changes like if a pattern is moved 1 pixel to the right this will give me a large error in number of different pixels. Is there a good way of do this kind of diff with ImageMagick? I have experimented with the fuzz parameter, but it really does not help me. Is ImageMagick compare only suited for comparing photographic images? Are there better switches to ImageMagick that can recognize a text that has moved some pixels and report it as equal? Should I use another tool?

Edit: Adding an example on a image that looks clearly different for a human and will illustrate the kind of difference I am trying to differentiate. In this image not many pixels are changed, but the visible pattern is clearly changed.

img3

1
What sort of differences are you hoping to detect or expecting to find?Mark Setchell
Added an example for an image that is different to a human.kungjohan

1 Answers

0
votes

It's hard to give any detailed answer as I don't know what you are looking for or expecting. I guess you may need some sort of Perceptual Hash if you are looking for images that people would perceive as similar or dissimilar, or maybe a Scale/Rotation/Translation Invariant technique that identifies similar images independently of resizes, shifts and rotations.

You could look at the Perceptual Hash and Image Moments with ImageMagick like this:

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

You could also go on Fred Weinhaus's excellent website (here) and download his script called moments which will calculate the Hu and Maitra moments and see if those will tell you what you want. Basically, you could run the script on each of your images like this:

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

and then use your favourite diff tool to see what has changed between the two images you wish to compare.