Composite with drawn mask requires TrueColor

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
tom_dl
Posts: 43
Joined: 2015-02-26T08:25:44-07:00
Authentication code: 6789

Composite with drawn mask requires TrueColor

Post by tom_dl » 2017-04-04T10:22:25-07:00

I have used the -composite option with 3 images to make a Masked Alpha Composition in the past like so:

Code: Select all

convert img1.tif img2.tif mask.tif -composite output.tif
But when I draw the mask rather than feed Imagemagick an image, this doesn't give expected results:

Code: Select all

convert input.tif \( -clone 0 -threshold 50372 \) \( -clone 0 -gamma -1 -fill black -draw "rectangle 128,504 425,826" \) -composite output.tif
Instead I need to use the -type option like so:

Code: Select all

convert input.tif \( -clone 0 -threshold 50372 \) \( -clone 0 -gamma -1 -fill black -draw "rectangle 128,504 425,826" \) -type TrueColor -composite output.tif
Why is the mask determining the image type rather than the 1st or 2nd image? Is it a bug that I should required -type TrueColor?

This is present in 7.0.3-7 but I can't upgrade to the latest version to see if this has been changed.

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite with drawn mask requires TrueColor

Post by fmw42 » 2017-04-04T11:15:54-07:00

Can you post your input TIFF file, so we can try your command? Why are you using -gamma -1? I thought -gamma was limited to values >0. What is the purpose of the -gamma -1?

Does this work for you? It seems to work fine for me using the logo: image. Note I have replace -gamma -1 with -fill white -colorize 100%, which seems to do the same as your -gamma -1 does. The output is type=palette.

Code: Select all

convert logo: \( -clone 0 -threshold 50% \) \( -clone 0 -fill white -colorize 100% -fill black -draw "rectangle 128,128 400,300" \) -composite output.tif

Code: Select all

convert logo: \( -clone 0 -threshold 50% \) \( -clone 0 -gamma -1 -fill black -draw "rectangle 128,128 400,300" \) -composite output.tif
http://www.fmwconcepts.com/misc_tests/output.tif

Tested with IM 6.9.8.3 Q16 Mac OSX and also IM 7.0.5.4 Q16 Mac OSX

tom_dl
Posts: 43
Joined: 2015-02-26T08:25:44-07:00
Authentication code: 6789

Re: Composite with drawn mask requires TrueColor

Post by tom_dl » 2017-04-06T06:34:27-07:00

Thanks for your reply! This TIFF file demonstrates the behaviour: https://www.dropbox.com/s/48ia9nquplfpa ... 9.tif?dl=0

I'm using -gamma -1 because http://www.imagemagick.org/Usage/canvas/#color_misc suggested it (it's really fast).

Neither of your lines works as intended for me, but adding -type TrueColor fixes both. I therefore assume this behaviour (I want to call it a bug, but I'm not sure what the intended behaviour is) is not caused by -gamma -1 or by the input image (I tried logo: and my TIFF and got the same results).

I get this with your line: https://www.dropbox.com/s/kfuebbphs9lk1 ... 2.tif?dl=0

And this when I add -type TrueColor:https://www.dropbox.com/s/0b5cw487yju6x ... T.tif?dl=0

Any idea if this is intended behaviour?

snibgo
Posts: 12306
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite with drawn mask requires TrueColor

Post by snibgo » 2017-04-06T07:01:54-07:00

tom_dl wrote:I'm using -gamma -1 because http://www.imagemagick.org/Usage/canvas/#color_misc suggested it (it's really fast).
When Anthony wrote that page, "-gamma" probably just changed pixel values. But now it also changes metadata, by multiplying the previous gamma value by the value you give. So the image now has negative gamma value. Try to save that as a PNG, and it is changed to a more sensible value, and you get a warning. But save it as a miff, and the negative metadata is saved.

I suggest that, if you use "-gamma -1" or "-gamma 0" or whatever, you should then immediately "-set gamma 0.454545", which changes just the metadata.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 12306
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite with drawn mask requires TrueColor

Post by snibgo » 2017-04-07T01:46:43-07:00

tom_dl wrote:Neither of your lines works as intended for me, but adding -type TrueColor fixes both.
Leaving aside the gamma issue, the problem occurs because some versions of v7, eg v7.0.3-6, generally regards the alpha channel when v6 generally ignored it. So the cure is to "-alpha off" the mask image.
snibgo's IM pages: im.snibgo.com

Post Reply