Modulus Subtract and Add

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Modulus Subtract and Add

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modulus Subtract and Add

Post 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.
Post Reply