Change language

Python PIL | Image.split () method

|

The Image.split () method is used to split an image into separate stripes. This method returns a set of individual image stripes from an image. 
Splitting an RGB image creates three new images, each containing a copy of one of the original stripes (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:

Output:

Code # 2:

# class import images from the PIL package

from PIL import Image

 
# opening a multiband image (specifically RGB)

im = Image. ope n (r "C: UsersAdminPictures etwork.png" )

 
# split () method
# this will split the image into separate stripes
# and return a tuple

im1 = Image.Image.split (im)

 
# shows each group

im1 [ 0 ]. show ()

im1 [ 1 ]. show ()

im1 [ 2 ]. show ()

# import image class from PIL package

from PIL import Image

 
# open a single page image

im = Image. open (r "C: UsersAdminPicturessingleband .png " )

  
< code class = "comments"> # split () method
# this will split the image into separate stripes
# and return a tuple (of 1 element for one range)

im1 = Image.Image.split (im)

 
# show the image

im1 [ 0 ]. show ()

Exit:

Images used: