Page 1 of 1
[RESOLVED] possible bug -evaluate-sequece sum IM 6.8.8.0
Posted: 2013-12-28T15:39:27-07:00
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:
This does not work correctly:
convert tmpR.png tmpG.png tmpB.png -evaluate-sequence
sum tmpRGB1.png
This does not work correctly:
convert tmpR.png tmpG.png tmpB.png -evaluate-sequence
add tmpRGB2.png
However, this alternate command works fine:
convert tmpR.png tmpG.png -compose plus -composite tmpB.png -compose plus -composite tmpRGB3.png
Is this a bug or some limitation of -evaluate-sequence sum or add?
Or am I not using the right argument?
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-28T18:05:43-07:00
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.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-28T18:55:26-07:00
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
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?
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-29T03:47:35-07:00
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.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T11:22:34-07:00
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
The expected results should look as follows:
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T13:28:24-07:00
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.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T13:49:28-07:00
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.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T17:05:16-07:00
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.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T17:25:04-07:00
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
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T17:31:21-07:00
by magick
Try now. It take a few minutes to build a new release.
Re: possible bug -evaluate-sequece sum IM 6.8.8.0 Q16 Mac OS
Posted: 2013-12-30T18:13:03-07:00
by fmw42
Works fine now in the latest 6.8.8.2 beta. Thanks