Skip to main content

transparency - 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).





Answer



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.


Comments