Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Python Imaging Library to isolate a single channel

So say I have an image, and I want to make it so that only the red channel shows up, and the image looks red, how would I do this using PIL? Thanks.

like image 699
jsmith Avatar asked Jul 16 '13 03:07

jsmith


People also ask

What is PIL image?

Python Imaging Library is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats. It is available for Windows, Mac OS X and Linux. The latest version of PIL is 1.1.

How do I use the pillow library in Python?

To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).

Is PIL and Pillow the same?

What is PIL/Pillow? PIL (Python Imaging Library) adds many image processing features to Python. Pillow is a fork of PIL that adds some user-friendly features.


1 Answers

You can use the Image.split() operation from PIL to separate the image into bands:

img = Image.open("image.jpg")
red, green, blue = img.split()

If the image has an alpha channel (RGBA) the split function will aditionaly return that. More information here.

like image 140
Anoyz Avatar answered Sep 25 '22 04:09

Anoyz