0 votes
in Python Imaging Library by
How can you use PIL to split an image into its R, G, B bands?

1 Answer

0 votes
by

The Python Imaging Library (PIL) provides the split() function to separate an image into its constituent R, G, B bands. To use this function, first import the PIL module and open your image using Image.open(). Then call the split() method on the opened image object. This will return a tuple containing three individual image objects for each color band. Here’s a simple example:

from PIL import Image

# Open image file

img = Image.open('image.jpg')

# Split into R, G, B

r_band, g_band, b_band = img.split()

In this code, ‘image.jpg’ is the image you want to split. The r_band, g_band, and b_band variables now hold the red, green, and blue components of the image respectively.

...