I am trying to find a way to get the number of channels of an image using Pillow. This seems rather trivial but I couldn't find it (the simple answer).
I know I can work it around with a minor overhead like (2 possibilities thought):
- Convert to numpy and check
array.shape - Check
image.size[0]*image.size[1]againstlen(image.getdata())
so I am not really interested in finding a working solution but rather in accomplishing this using pillow.
The code I am using is straight forward:
from PIL import Image
image = Image.open(image_path)
image.size # <- this gives the size of the image but not the channel as in numpy.
(609, 439)
I also found this approach inspired by this answer (which also imports overhead of course):
num_channel = len(image.split())
To me it seems really peculiar I cannot find this simple answer.