Page 1 of 1

Determine original image type (RGBA or only alpha)

Posted: 2010-05-20T03:56:28-07:00
by ismfismf
Hi!

I have looked through the forum, but could not find an answer. I have troubles to tell an RGBA image apart from a black/white image.

If a PNG or TGA image is stored as RGBA, but the whole image is transparent, then ImageMagick always returns type BilevelType and color space RGBColorspace when reading the file. How can I tell that apart from a real bilevel image (indexed black/white with transparency)?

Image *image = new Image();
image->adjoin(true);
image->read(filename);
ImageType image_type = image->type(); // is BilevelType
ColorspaceType colorType = image->colorSpace(); // is RGBColorspace

If ImageMagick does some automatic quantization/color reduction, how can I turn that off for reading an image (for the sample code above).

Thanks.

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-05-20T05:12:46-07:00
by ismfismf
BTW, the version of ImageMagick is 6.6.0.

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-05-20T09:35:22-07:00
by fmw42
In command line you can use -format "%[channels]" info:

convert logo: -format "%[channels]" info:
rgb

convert logo: -transparent white -format "%[channels]" info:
rgba

convert logo: -colorspace gray -format "%[channels]" info:
gray

convert logo: -type grayscale -format "%[channels]" info:
gray



convert logo: -monochrome -format "%r" info:
pseudoclassgray

convert logo: -format "%r" info:
PseudoClassRGB

convert logo: -transparent white -format "%r" info:
DirectClassRGBMatte


see http://www.imagemagick.org/script/escape.php

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-05-20T12:57:27-07:00
by ismfismf
This works. Thanks.

I actually need the same as C++ call. Any idea which method does the same?

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-05-20T14:02:38-07:00
by fmw42
Sorry I only use command line. Hopefully someone else can point you in the right direction.

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-07-07T05:38:56-07:00
by ismfismf
Does anyone have an idea how to get the right format programmatically?

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-08-04T04:12:40-07:00
by ismfismf
Anyone any idea?

Re: Determine original image type (RGBA or only alpha)

Posted: 2010-08-05T19:59:59-07:00
by fmw42
FYI: see viewtopic.php?f=3&t=16794 for issues related to string format [channels]