Page 1 of 1

Modulus Subtract and Add

Posted: 2013-10-26T19:53:25-07:00
by snibgo
Documentation http://www.imagemagick.org/Usage/compos ... s_subtract states "This operator [ModulusSubtract] is not recommended for use in any situation, as 'ModulusAdd' with a Negated Image will provide the same result." But this isn't quite true because black is zero and white is 65535 (in Q16), and 65535 is treated as -1 in modulus arithmetic. -1 is close, but not equal, to zero.

(In addition, the link is broken, and should be to http://www.imagemagick.org/Usage/color_mods/#negate .)

The following commands show the difference:

convert xc:#000100020003 m.png

convert m.png txt:
#000100020003

convert xc:black m.png -compose ModulusSubtract -composite txt:
#000100020003

convert ( xc:black -negate ) m.png -compose ModulusAdd -composite txt:
#000000010002

We can cure the problem by adding 1:

convert ( xc:black -negate ) m.png -compose ModulusAdd -composite -evaluate AddModulus 1 txt:
#000100020003

Tested under IM v6.8.7-1 on Windows 7.

Re: Modulus Subtract and Add

Posted: 2013-10-27T03:49:48-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.8.7-4 Beta available by sometime tomorrow. Thanks.