Page 1 of 1

How can I find out how many channels an image has?

Posted: 2008-06-11T18:38:49-07:00
by fmw42
Is there a string format for the number of channels in an image or whether there is an alpha channel present? If not, both might be useful string formats to have? I could use it in one of my scripts.

Or is there some other easy way to identify that?

Re: How can I find out how many channels an image has?

Posted: 2008-06-11T22:18:54-07:00
by anthony
The color space will define either 3 (most of the spaces) or 4 (CMYK only) color channel The K channel also being used for color palete index generation for quantization. The Alpha is optional to all color spaces.

So image has 3 color channels normally, add one if it is CMYK and add another if alpha channel is turned on.

That is it.

Gray is a 'pseudo' colorspace in that it is faked using a 3 channel RGB colorspace.

Re: How can I find out how many channels an image has?

Posted: 2008-06-11T23:40:21-07:00
by fmw42
How do I distinguish between rgba and cmyk? Both have 4 channels? Colorspace will be CMYK for the latter, but only RGB for the former. So how do I know if I have rgb + a?

How do I identify gray + alpha? Will it be 2 channels or 4?

Re: How can I find out how many channels an image has?

Posted: 2008-06-11T23:45:56-07:00
by anthony
The color space is given either in identify or in the header of the TXT format.
In fact the number of letters in that format = the number of channels!!!!

So if you see rgba you have 4 channels the last of which is an alpha/matte channel.

Re: How can I find out how many channels an image has?

Posted: 2008-06-12T09:44:24-07:00
by fmw42
identify -verbose does not put RGBA for the colorspace, only RGB even if it has an alpha present and identify without the -verbose does not list the colorspace

txt: looks like the way to go