# Check if image has alpha channel

How can I check if an Image has an alpha channel?

"What have you tried?"

• AlphaChannel and ColorSeparate[..., "A"] return a result even if the image had no explicit alpha channel.

• We could check the number of results from ColorSeparate or ImageChannels, but that also depends on ColorSpace, which may also be a ColorProfileData object (for which it isn't clear how to determine the number of expected channels).

## 3 Answers

I just discovered this command (in the Properties and Relations sections of the AlphaChannel command)

ImageMeasurements[img, "Transparency"]


It returns True if there is an alpha channel and False otherwise.

• It's a weird place to put this functionality, isn't it? It relies on ImageImageInformation which is a much more natural name for something like this. "Measurement" implies work/computation. Of course it was in the AlphaChannel documentation, so this is the kind of question that usually gets closed as "easily (?) found in the documentation". Oct 9 '17 at 22:38
• I was surprised at the whole ImageMeasurements command. It seems like an odd complement to ComponentMeasurements (which also takes images as input). Oct 9 '17 at 23:04

How about this:

RemoveAlphaChannel[img] == img


If img has no alpha channel, this returns True, but returns False if img has an alpha channel.

SetAlphaChannel[img] == img


seems to work too, but with the reverse logic.

• This works. What I don't love about it is that the performance depends on the image size. There should be a constant time way. Oct 9 '17 at 21:34

As of V12, Information can return this:

Information[ExampleData[{"TestImage", "Lena"}], "Transparency"]

False
`