Page 1 of 1
how can I find out number of color components per pixel
Posted: 2011-03-24T08:45:43-07:00
by jstph
Is there anyway I can find out how many color components per pixel after I load image data as Image?
I try to use image->colorspace to identify, it doesn't work. I also try to use image->type, however for ColorSeparationType and UndefinedType, it will not work. I must miss something here.
I am also not sure if I can use image->matter to identify the transparent or not.
Can anyone give me a hint. Thanks in advance.
Re: how can I find out number of color components per pixel
Posted: 2011-03-24T09:20:35-07:00
by magick
A colorspace of RGB suggests at least 3 color components per pixel. Add 1 if image->matte != MagickFalse (for alpha) channel. A colorspace of CMYK suggests at least 4 color components per pixel. Add 1 if image->matte != MagickFalse (for alpha) channel.
Re: how can I find out number of color components per pixel
Posted: 2011-03-24T23:21:32-07:00
by anthony
Only if combined with a 'type' that isn't greyscale! Remember IM fakes grayscale by using RGB
But generally that is correct 4 for CMYK otherwise it is 3, then add 1 if transparency is present.
Re: how can I find out number of color components per pixel
Posted: 2011-03-28T10:32:57-07:00
by fmw42
try
convert image -format "%[channels]" info:
that should report
rgb
rgba
gray
graya
cmyk
cmyka
Re: how can I find out number of color components per pixel
Posted: 2011-04-06T07:56:04-07:00
by jstph
Thanks for all comments.
At the end, I did as anthony suggested. If the color space is RGB, then check image type. If image type is grayscale or Bilevel, the number of component should be one. otherwise, it is either 3 or 4 depending on color space.
However, I does have something unsure of PaletteBilevelMatteType. Is it one color index plus one alpha or just one color index which include alpha in its color palette? Right now, I transformed it to RGB.
Re: how can I find out number of color components per pixel
Posted: 2011-04-07T01:01:39-07:00
by anthony
PaletteBilevelMatteType I would assume this is an image with only three posible valid colors.
Black White and Transparent. Channel wise it is two channels, greyscale (bitmap) plus alpha.