Page 1 of 1

Composite with drawn mask requires TrueColor

Posted: 2017-04-04T10:22:25-07:00
by tom_dl
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.

Re: Composite with drawn mask requires TrueColor

Posted: 2017-04-04T11:15:54-07:00
by fmw42
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

Re: Composite with drawn mask requires TrueColor

Posted: 2017-04-06T06:34:27-07:00
by tom_dl
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?

Re: Composite with drawn mask requires TrueColor

Posted: 2017-04-06T07:01:54-07:00
by snibgo
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.

Re: Composite with drawn mask requires TrueColor

Posted: 2017-04-07T01:46:43-07:00
by snibgo
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.