masked compose plus vs compose multiply, then plus

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hwttdz
Posts: 22
Joined: 2010-08-29T05:29:08-07:00
Authentication code: 8675308

masked compose plus vs compose multiply, then plus

Post by hwttdz »

I tried two different ways of getting what I expect to be the same output, the first is:

C = A * mask;
output = C + B;

or in nearer IM syntax

composite -compose multiply mask A C
composite -compose plus C B output

and the second is

convert B A mask -compose plus -composite output

which should give B + A * mask, which is the same as above. However the images produced (while similar) are different. compare -metric rmsd gives 807.5 (0.012), or if I view the images in sequence in a slide show there is a clear difference.
Last edited by hwttdz on 2011-04-19T13:09:44-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: masked compose plus vs compose multiply, then plus

Post by fmw42 »

hwttdz wrote:I tried two different ways of getting what I expect to be the same output, the first is:

C = A * mask;
output = C + B;

or in nearer IM syntax

composite -compose multiply mask A C
composite -compose plus C B output

and the second is

compose B A mask -compose plus -composite

which should give B + A * mask, which is the same as above. However the images produced (while similar) are different. compare -metric rmsd gives 807.5 (0.012), or if I view the images in sequence in a slide show there is a clear difference.

I believe your syntax (composite -compose multiply mask A C) is flawed. see http://www.imagemagick.org/Usage/compose/#compose

composite {overlay} {background} [{mask}] [-compose {method}] {result}

Personally, I prefer to use convert ... -compose ... -composite , since you can do all steps in one command.
hwttdz
Posts: 22
Joined: 2010-08-29T05:29:08-07:00
Authentication code: 8675308

Re: masked compose plus vs compose multiply, then plus

Post by hwttdz »

Sorry, I'm actually using convert -compose -composite (as suggested) and mangled it up in my attempt to post a minimum working example. So the ordering is correct. I'll try to update in original post.

I've switched to ppm from jpg and my error has gone down from 807.5 (0.012) to 667.7 (0.010). The difference between these two images is still very visible however.

Extending the above suggestion of using convert -compose -composite and combining commands (and using ppm for intermediate steps) I have continued to reduce the error. There is now no visibly apparent difference between the images. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: masked compose plus vs compose multiply, then plus

Post by fmw42 »

best to post your actual commands in a new reply rather than change what you have above or the other replies will confuse people

You can edit your original post and put a link to see the correction below
Post Reply