Python PIL library contains Image module in which variety of functions are defined. PIL.Image.Image.getbands()
This method is used to get the mode (bands) present in an image.
Syntax: PIL.Image.Image.getbands(image_object [valid image path])
Parameters:
It takes a parameter image_object i.e it the reference of the image which is opened uisng open() method or image path can also be mentioned.Return value: Returns a tuple containing the name of each band in this image. For example, getbands on an RGB image returns (“R”, “G”, “B”).
# Importing Image module from PIL package from PIL import Image # Opening a multiband image im = Image.open(r"C:\Users\Admin\Pictures\images.png") # This returns the bands used in im (image) im1 = Image.Image.getbands(im) print("Multiband image", im1) # Opening a single band image im2 = Image.open(r"C:\Users\Admin\Pictures\singleband.png") # This returns the band used in im2 im3 = Image.Image.getbands(im2) print("Single band image", im3) |
Output:
Multiband image ('R', 'G', 'B')
Single band image ('P', )
PIL.Image.Image.getextrema() method –
Gets the the minimum and maximum pixel values for each band in the image.
Syntax: PIL.Image.Image.getextrema(image_object [valid image path])
Parameters:
It takes a parameter image_object i.e it the reference of the image which is opened uisng open() method or image path can also be mentioned.Return Value: For a single-band image, a 2-tuple containing the minimum and maximum pixel value. For a multi-band image, a tuple containing one 2-tuple for each band.
# importing Image module from PIL package from PIL import Image # opening a multiband image im = Image.open(r"C:\Users\Admin\Pictures\download.png") # getting maximum and minimum pixels of # multiband images (RBG) im1 = Image.Image.getextrema(im) print("Multi band image ", im1) # Opening a single band image im2 = Image.open(r"C:\Users\Admin\Pictures\singleband.png") # getting maximum and minimum pixels of # single band image im3 = Image.Image.getextrema(im2) print("Single band image ", im3) |
Output:
Multi band image ((73, 255), (0, 255), (0, 255)) Single band image (0, 123)
These images used in above article –
Multiband Images


Single band Image

Recommended Posts:
- Python PIL | getbands() method
- Python PIL | logical_and() and logical_or() method
- Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method
- Python PIL | ImageEnhance.Color() and ImageEnhance.Contrast() method
- Python PIL | ImageChops.screen() and ImageChops.offset() method
- Python PIL | MedianFilter() and ModeFilter() method
- Python PIL | paste() and rotate() method
- Python PIL | MinFilter() and MaxFilter() method
- Python PIL | ImageChops.add_modulo() and ImageChops.difference() method
- Python PIL | ImageEnhance.Brightness() and ImageEnhance.Sharpness() method
- Python PIL | logical_xor() and invert() method
- Python PIL | GaussianBlur() method
- Python PIL | Kernel() method
- Python PIL | BoxBlur() method
- Python PIL | ImageChops.subtract() method
- Python PIL | UnsahrpMask() method
- Python PIL | Image.crop() method
- Python PIL | ImageOps.expand() method
- Python PIL | ImageGrab.grabclipboard() method
- Python PIL | RankFilter() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

