"-compose plus -layers flatten" alway produces a blank white image
Example:
convert logo: logo: -compose plus -layers flatten test.png
Blank image
convert logo: logo: -compose plus -composite test.png
Correct output
compose multiply -layers flatten has no such problems
convert logo: logo: -compose multiply -layers flatten test.png
also correct
but some other methods like compose screen -layers flatten also do not work correctly
ImageMagick 6.5.5-2 2009-08-25 Q16
[resolved - no bug] -compose plus -layers flatten
[resolved - no bug] -compose plus -layers flatten
Last edited by HugoRune on 2009-08-26T19:05:01-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: -compose plus -layers flatten
same with -compose minus -layers flatten
but -compose add -layers flatten does produce a non-white result (but add vs plus will wrap-around in grayscale)
but -compose add -layers flatten does produce a non-white result (but add vs plus will wrap-around in grayscale)
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: -compose plus -layers flatten
convert logo: logo: -compose plus -layers flatten test.png
pure white image!
that is correct output because you are really doing three compose operations
( background + logo: ) + logo: ) -> white
Background color defaults to white so the image goes beyond white and clipped at white.
This is NOT a bug, but a miss-understanding of how the operator works.
This is the way all 'layer merging' type operators work 'flatten' 'mosaic' 'merge'.
Actually it is also similar to how border, extent, frame works too, just with
different canvas color sources.
Now if you want a equivalent of a multiply by 2 then set background to black!!!
convert logo: logo: -background black -compose plus -layers flatten test.png
And you will get the right answer.
However as you are using two images only and no transparency why not use -composite instead!
convert logo: logo: -compose plus -composite test.png
no background will be involved then!
pure white image!
that is correct output because you are really doing three compose operations
( background + logo: ) + logo: ) -> white
Background color defaults to white so the image goes beyond white and clipped at white.
This is NOT a bug, but a miss-understanding of how the operator works.
This is the way all 'layer merging' type operators work 'flatten' 'mosaic' 'merge'.
Actually it is also similar to how border, extent, frame works too, just with
different canvas color sources.
Now if you want a equivalent of a multiply by 2 then set background to black!!!
convert logo: logo: -background black -compose plus -layers flatten test.png
And you will get the right answer.
However as you are using two images only and no transparency why not use -composite instead!
convert logo: logo: -compose plus -composite test.png
no background will be involved then!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: -compose plus -layers flatten
fmw42 wrote:same with -compose minus -layers flatten
but -compose add -layers flatten does produce a non-white result (but add vs plus will wrap-around in grayscale)
-compose add and -compose substract are modulus operators, that is the values wrap at white and black. They are also effected by background, but white is almost exactly the same as black, or zero, so their is little effect from the default background.
However with a 'flatten' background is still involved and the background color can be used (and is used) to set a 'phase' type offset to the modulus addition/subtraction.
Remember multi-image layer merging, 'flatten', 'mosaic', and 'merge' all work by starting with a background canvas, then subtracting each image from that canvas.
(..( background OP image1 ) OP image2 ) OP image 3 )....
Multiply is unaffected as white is a image * 1.0 which is the image.
Screen is effected as image SCREEN 1.0 => 1.0 (use back instead)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: -compose plus -layers flatten
I see, that makes sense, thanks!anthony wrote: that is correct output because you are really doing three compose operations
( background + logo: ) + logo: ) -> white
I assumed the background was always an implicit "under" composition, no matter what.
Do i have to set the background depending on what type of composition I use, or is there a "None" background that has no effect in all cases?
I simplified the test case. I actually have a least 4 images at a time I want to add ( and they are not all identical either )anthony wrote:However as you are using two images only and no transparency why not use -composite instead!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: -compose plus -layers flatten
No it is an implicit starting canvas onto which images are layered, which is created from a clone of the first image (so it gets the first images meta-data) and sized according to the requires result of the layer operation (which is how the operators differ).HugoRune wrote:I assumed the background was always an implicit "under" composition, no matter what.
Usually the default composition is 'Over' which places image on top (over) the background and previous images. However I have used -background none -compose DstOver to place images under each other (reversed order).
Actually almost all the mathematical operators use an 'over' alpha blending. As such anything that is transparent does not take part. Also the order is reversed, which is important operators that matter (like minus and divide)
So by using -background none for any mathematical layering the canvas will not take part in the mathematics, with the first image just simply layers over the canvas.
-background none image1 image2 -compose minus -layer flatten
will place image 1 over 'none' then subtract that from image 2
where as using black would produce
image2 - ( image1 - black)
Note the order of operations! For minus (or division) that can be critical!
None generally has no effect, due to 'Over' alpha blending used by MOST mathematical operators (see above). 'Over' alpha blending is equivalent to a mathematical multiply of just the alpha values, but has extra effects on semi-transparent color mixing. Its handling is very precisely defined by the SVG specification for image composition.Do I have to set the background depending on what type of composition I use, or is there a "None" background that has no effect in all cases?
However 'over' blending is not used for: plus, subtract, add, minus; as the alpha values are also mathematically applied! Only the 'plus' method is defined in the SVG document, and it is important that is is handled in this way. IM is the only one to implement the other three, that I know of, but they follow the same convention as 'plus' for alpha handling. See...
http://www.imagemagick.org/Usage/compose/#plus_blend
If over alpha blending is important then 'linear_dodge' is equivalent to 'plus' but with over alpha blending.
image2 plus image1 == image2 linear_dodge image1
when no transparency is involved.
Also if you negate an image to be subtracted you can use 'linear_burn' to 'minus' and image with 'over' alpha blending.
image2 minus image1 == image2 linear_burn ( image1 negate )
again these are equally only when semi-transparency is not involved and over alpha blending is wanted. This is actually the way photoshop does image subtraction!
Look at the raw tables of composition
http://www.imagemagick.org/Usage/compose/tables/
For more detail download my compose operator testing script
http://www.imagemagick.org/Usage/scripts/compose_table
and run
Code: Select all
compose_table -mb
HugoRune wrote:I simplified the test case. I actually have a least 4 images at a time I want to add ( and they are not all identical either )
Then just set -background to black and all will be well! I have done this for example to add together the differences of the three color channels.
See Image Comparing, Difference Images
http://www.imagemagick.org/Usage/compare/#differenceCode: Select all
convert bag_frame1.gif bag_frame2.gif -compose difference -composite \ -separate -background black -compose plus -flatten \ difference_plus.gif
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/