Python PIL | Image.split() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.

Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image.
Splitting an “RGB” image creates three new images each containing a copy of one of the original bands (red, green, blue).

Syntax:
var = Image.Image.split(image_object)
OR
var = Image.Image.split(path_of_image)

Return Value: It returns a tuple containing bands.

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing Image class from PIL package
from PIL import Image
  
# opening a multiband image (RGB specifically)
im = Image.open(r"C:\Users\Admin\Pictures\network.png")
  
# split() method
# this will split the image in individual bands
# and return a tuple
im1 = Image.Image.split(im)
  
# showing each band
im1[0].show()
im1[1].show()
im1[2].show()

chevron_right


Output:

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing Image class from PIL package
from PIL import Image
  
# opening a singleband image
im = Image.open(r"C:\Users\Admin\Pictures\singleband.png")
  
# split() method
# this will split the image in individual bands
# and return a tuple (of 1 element for singleband)
im1 = Image.Image.split(im)
  
# showing image
im1[0].show()

chevron_right


Output:

Images Used:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.