Page 1 of 1

Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-06T22:05:46-07:00
by quicksnap
Hello! I'm trying to do this with the C API (not C++), but I'm able to replicate this problem with "convert".

I am trying to consistently flatten TIFFs against a white background. When I encounter a TIFF that has transparency disabled, but contains an auxiliary alpha channel, Image Magick considers that channel the transparency channel, and results are not good.

I have two input TIFF files--one with transparency enabled, one with it disabled. Both have a checkerboard background in Photoshop. I am using the "Enable Transparency" in the Save As dialog within Photoshop.

Both files have an additional channel added within Photoshop containing some brush strokes of leaves.

The sample files are here:

Without Transparency: https://www.dropbox.com/s/fli26u0u4f25i ... y.tif?dl=0
With Transparency: https://www.dropbox.com/s/s1aidyct4oqib ... .tif?dl=0z

Here are the commands I run against them:

Code: Select all

convert with-transparency.tif -background white -alpha off -flatten out/whiteAlphaOffFlatten.tif
convert with-transparency.tif -background white  -flatten out/whiteFlatten.tif
convert without-transparency.tif -background white  -flatten out/without-whiteFlatten.tif
convert without-transparency.tif -background white -alpha off -flatten out/without-whiteAlphaOffFlatten.tif
And these are the output results: https://dl.dropboxusercontent.com/spa/4 ... 5rm_ae.png

I would love some input on how I can flatten these suckers! Am I doing something wrong? This is driving me bonkers!

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-06T23:32:13-07:00
by fmw42
Both your files are the same. They both have a disabled alpha channel when I open them in PS (CS), though that may not be how they were saved. Both also have background transparency. Probably, IM can only deal with one or the other, as far as I know, unless there is a new -define to select which one. They are also both CMYK (with USWebCoatedSwop.icc profile) and not RGB. I would convert to RGB using profiles before flattening.

These work for me in IM 6.1.9.10 Q16 Mac OSX Snow Leopard

Code: Select all

convert with-transparency.tif -profile /users/fred/images/profiles/sRGB.icc -background white -compose over -flatten with_flattened.tif

convert without-transparency.tif -profile /users/fred/images/profiles/sRGB.icc -background white -compose over -flatten without_flattened.tif

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-06T23:53:05-07:00
by quicksnap
Thanks for your help! I tried your command, and it didn't work.. however, I was using an older version of Image Magick (6.8.9), and I tested it against 6.9.1-10, and it works on that version for both files! Time to rev..

Thanks again!

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-06T23:53:48-07:00
by quicksnap
You wouldn't happen to know the C API calls to replicate your convert command above, do you?

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T09:08:36-07:00
by fmw42
Sorry, I do not know any of the IM APIs only command line.

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T17:16:32-07:00
by quicksnap
Once again, I'm at an impasse. Consider the following TIF: https://www.dropbox.com/s/usn9jv0protgijv/bad.tif?dl=0

When I run the following command, trying to convert it to a JPEG, it chokes:

Code: Select all

convert bad.tif -profile ./sRGB.icc -background white -compose over -flatten ugly.jpg
The problem is that this TIFF contains an alpha channel but has "transparency disabled" according to Photoshop.

Is the replicable outside my system on ImageMagick 6.9.1-10 Q16?

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T18:14:18-07:00
by fmw42
It works fine for me on IM 6.9.1.10 Q16 Mac OSX.

If you want to flatten the alpha to white, then do

Code: Select all

convert bad.tif -profile /users/fred/images/profiles/sRGB.icc -background white -compose over -flatten bad_test1.tif
If you want to remove the alpha, then do

Code: Select all

convert bad.tif -alpha off -profile /users/fred/images/profiles/sRGB.icc -background white -compose over -flatten bad_test2.tif

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T18:45:31-07:00
by quicksnap
Well, the problem with this is that the alpha channel is not a "transparency" channel. If you open that TIFF in Photoshop, you will not see any transparency--only the normal image with an additional channel:

https://dl.dropboxusercontent.com/spa/4 ... 2xou4p.png

The problem is that I need a way to detect this non-transparent alpha channel, so that I can run a conversion across all TIFFs, some of which have a standard alpha channel which needs to be flattened and cannot be removed.

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T19:20:00-07:00
by snibgo
The problem is that I need a way to detect this non-transparent alpha channel ...
Quite possibly this can come from identify -verbose "tiff:alpha", of exiftool "IFD0:ExtraSamples".

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T19:34:50-07:00
by fmw42
The problem is that I need a way to detect this non-transparent alpha channel, so that I can run a conversion across all TIFFs, some of which have a standard alpha channel which needs to be flattened and cannot be removed.
Please clarify you comment. Why do not you need to detect alpha?

If you flatten the image whether it has alpha or not, my first command will work. If there is no alpha, it does not matter.

If you never want to to see the alpha as white when flattening, then the second command will work whether there is alpha or not.

Re: Inconsistent alpha flattening of transparent TIFs

Posted: 2015-08-07T21:51:42-07:00
by snibgo
I think his question is, "When I have an alpha, how do I know if it represents transparency?"

I think the answer is to look at identify -verbose "tiff:alpha", or exiftool "IFD0:ExtraSamples".