[RESOLVED] possible bug -evaluate-sequece sum IM 6.8.8.0

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

[RESOLVED] possible bug -evaluate-sequece sum IM 6.8.8.0

Post by fmw42 »

convert -version
Version: ImageMagick 6.8.8-0 Q16 x86_64 2013-12-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib



I am not sure if this is a bug or some limitation, but I cannot get -evaluate-sequence sum or add to produce a "correct" result when there is an alpha channel in each image.

I even tried adding -alpha on -channel rgba or -alpha on -channel rgba,sync but neither helped.

Here is what I tried:

Input:

Image Image Image


This does not work correctly:

convert tmpR.png tmpG.png tmpB.png -evaluate-sequence sum tmpRGB1.png

Image


This does not work correctly:

convert tmpR.png tmpG.png tmpB.png -evaluate-sequence add tmpRGB2.png

Image


However, this alternate command works fine:

convert tmpR.png tmpG.png -compose plus -composite tmpB.png -compose plus -composite tmpRGB3.png

Image


Is this a bug or some limitation of -evaluate-sequence sum or add?

Or am I not using the right argument?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by magick »

The 'add' and 'sum' operators, adds the three images together then clamps. So its
  • clamp(R1+R2+R3)
    clamp(G1+G2+G3)
    ...
For Q8, if R1=R2=R3=100, clamp(R1+R2+R3) is 255.

If you feel the algorithm should behave differently, let us know.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by fmw42 »

Part of the issue was that the transparent parts were transparent white. So by changing the transparent areas to none (transparent black), I get closer. But I do not understand why the fully opaque areas (where red, green and blue overlap) in the combined image turns transparent rather than white and transparent parts turn opaque black. This is very odd. Perhaps it has to do with how transparency is handled or not handled.

convert tmpR.png tmpG.png tmpB.png -background none -alpha background -evaluate-sequence sum tmpRGB_none.png

Image


It is not urgent, since I have a workaround. So I am just trying to understand and make sure it is working properly when all 3 images have transparent regions.

So how is the alpha channel included in -evaluate-sequence results?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.8-1 Beta, available by sometime tomorrow. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by fmw42 »

I do not think we are getting the right results still in IM 6.8.8.1 Q16 Mac OSX. It is missing the opaque red and yellow areas. I am not sure if this is still a bug or just the way -evaluate-sequence algorithm differs from using two -compose plus -composite operations as in my first post.

Here is my test using the same input images as above.

convert tmpR.png tmpG.png tmpB.png -background none -alpha background -evaluate-sequence sum tmpRGB_none2.png

Image


The expected results should look as follows:


Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by magick »

The add op of the -evaluate-sequence is purely mathematical. Take location 102,101, for example. The R image is 255,0,0. Whereas the G and B images are 255,255,255 at that location. Adding these together as clamp(R1+R2+R3), clamp(G1+G2+G3), etc., returns 255,255,255, or white, not red as you would expect. The -composite Plus op scales by the alpha channel to get the desired result (transparent white is mathematically 0), the -evaluate-sequence treats the channels independently.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by fmw42 »

The white part is fine. I am more concerned about the red and yellow parts.

I believe you may have overlooked the -background black (or none) -alpha background in the command so that where there is only red and the other two images are transparent, the underlying values should be r=255,g=0,b=0 which should produce red. Likewise where there is red and green and blue is transparent, r=255,g=255,b=0 and the result should be yellow.

convert tmpR.png tmpG.png tmpB.png -background black -alpha background -evaluate-sequence sum tmpRGB_none3.png

What I am not sure about is how the alpha channel affects the addition process. If one or two images are transparent and the other is opaque as in the red area of the correct result, will -evaluate-sequence make it transparent or opaque. What I may be incorrectly expecting is that the only transparent part should be where all 3 images are transparent. That would be the case if the alpha channels were simply added together or used the largest value.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by magick »

Ok, got it. The problem is that we must treat the channel as alpha rather than opacity. With the latest patch, it returns the expected results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by fmw42 »

OK, not urgent, but let me know when it is in the 6.8.8.2 beta. I just tried and it does not seem to be there or gives the same results as before. Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by magick »

Try now. It take a few minutes to build a new release.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS

Post by fmw42 »

Works fine now in the latest 6.8.8.2 beta. Thanks
Post Reply