Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Python PIL | getbands() method

  • Last Updated : 29 Jul, 2019
PIL is the Python Imaging Library which provides the python interpreter with image editing
capabilities. PIL.Image.getbands() method returns a tuple containing the name of each band in the image.For example, getbands on an RGB image returns (“R”, “G”, “B”).

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Syntax: PIL.Image.getbands()
Parameters: no arguments
Returns: A tuple containing band names.




# Importing Image module from PIL package 
from PIL import Image
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")
  
# get bands of image
im2 = im1.getbands()
  
# print band names.
print(im2)

Output:
(‘R’, ‘G’, ‘B’, ‘A’)

Image used above is:




# Importing Image module from PIL package 
from PIL import Image
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\r1.PNG")
  
# get bands of image
im2 = im1.getbands()
  
# print band names.
print(im2)

Output:
(‘P’, )

Image used above is:

My Personal Notes arrow_drop_up
Recommended Articles
Page :