HugoRune wrote:I assumed the background was always an implicit "under" composition, no matter what.
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).
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!
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?
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.
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
Option -mb is for mathematics operators with alpha blending tests. This is what I have been using to debug the compose operators.
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/#difference
Code: Select all
convert bag_frame1.gif bag_frame2.gif -compose difference -composite \
-separate -background black -compose plus -flatten \
difference_plus.gif