Menu

#642 Result of command "gm compare" depends on order of images

v1.0_(example)
closed-fixed
5
2021-05-02
2021-04-01
No

Result of command "gm compare" depends on order of images if one of image has transparency and other one doesn't have.

For example, we have images:
butterfly_with_transparent_bg.png - with transparency
butterfly_with_black_bg.png - without transparency

If we compare images and the first image is image with transparency it works correct:

> gm compare -metric mae butterfly_with_transparent_bg.png butterfly_with_black_bg.png 
Image Difference (MeanAbsoluteError):
           Normalized    Absolute
          ============  ==========
     Red: 0.0000000000        0.0
   Green: 0.0000000000        0.0
    Blue: 0.0000000000        0.0
 Opacity: 0.5739548742    37614.1
   Total: 0.1434887186     9403.5

But if we change the order of images, gm compare doesn't see any differences:

> gm compare -metric mae butterfly_with_black_bg.png butterfly_with_transparent_bg.png
Image Difference (MeanAbsoluteError):
           Normalized    Absolute
          ============  ==========
     Red: 0.0000000000        0.0
   Green: 0.0000000000        0.0
    Blue: 0.0000000000        0.0
   Total: 0.0000000000        0.0
2 Attachments

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2021-04-02

    The reason for this behavior is that the first image is the "reference" image. From reading the source code, it appears that if the -matte option is added like:

    gm compare -matte -metric mae butterfly_with_black_bg.png butterfly_with_transparent_bg.png

    that the opacity channel will always be included in the compare and the image without a matte channel has its matte channel set to opaque. If one uses +matte then the opacity channel should be ignored.

    I am not sure if the reason is a good reason.

     
  • Vitalii Martenkov

    I tried gm compare -matte -metric mae butterfly_with_black_bg.png butterfly_with_transparent_bg.png and it returned the same result.

    Then I tried gm compare +matte -metric mae butterfly_with_transparent_bg.png butterfly_with_black_bg.png and it likes that option mate doesn't have any effect.

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2021-04-02

      On Fri, 2 Apr 2021, Vitalii Martenkov wrote:

      I tried gm compare -matte -metric mae butterfly_with_black_bg.png butterfly_with_transparent_bg.png and it returned the same result.

      Then I tried gm compare +matte -metric mae butterfly_with_transparent_bg.png butterfly_with_black_bg.png and it likes that option mate doesn't have any effect.

      It seems like this issue needs more consideration and analysis so it
      both does what was intended, and what the user most likely expects.

      Bob

      Bob Friesenhahn
      bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
      GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
      Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

       
  • Bob Friesenhahn

    Bob Friesenhahn - 2021-05-02
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2021-05-02

    In my own testing, adding -matte does have the indended effect of enabling the opacity channel even though the first image does not have an opacity channel. Regardless my original assumption that the user knows that the first image is the original and wants the comparison to be done in terms of the original is somewhat faulty and I plan to fix that.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2021-05-02
    • status: open --> closed-fixed
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2021-05-02

    This problem is addressed by Mercurial changeset 16520:39f63789f297. Thanks for bringing it to our attention.

     

Log in to post a comment.

MongoDB Logo MongoDB