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.
how can I find out number of color components per pixel
Re: how can I find out number of color components per pixel
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: how can I find out number of color components per pixel
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.
But generally that is correct 4 for CMYK otherwise it is 3, then add 1 if transparency is present.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how can I find out number of color components per pixel
try
convert image -format "%[channels]" info:
that should report
rgb
rgba
gray
graya
cmyk
cmyka
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
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.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: how can I find out number of color components per pixel
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.
Black White and Transparent. Channel wise it is two channels, greyscale (bitmap) plus alpha.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/