.point()
Anonymous contributor
Published Apr 25, 2025
Contribute to Docs
In Pillow, the .point()
method is used to apply a function or lookup table to each pixel in an image. It is useful for performing operations like thresholding, gamma correction, or channel manipulation.
Syntax
Image.point(lut, mode=None)
Parameters:
lut
: This parameter can be:- A lookup table: A list or sequence with 256 values for 8-bit images per band (e.g., 768 values for RGB). For 16-bit images, 65536 values are required per band.
- A function: Takes a single integer (0–255) and returns a value. It’s called once for each possible pixel value to build a lookup table internally.
mode
(optional, str): The mode of the output image. Use this if you want to change the image type during transformation. Common modes include:"L"
: 8-bit pixels, black and white (grayscale)"RGB"
: 3x8-bit pixels, true color"RGBA"
: 4x8-bit pixels, true color with alpha channel"1"
: 1-bit pixels, black and white"P"
: 8-bit pixels, uses a color palette to map to other modes
Note: Most uses of
.point()
don’t require the argumentmode
unless there is a need to explicitly change the image type (e.g., converting grayscale to binary).
Return value:
This method returns a new Image
object with the transformed pixel data.
Example
This example creates a horizontal grayscale gradient, inverts it using .point()
, and saves the result:
from PIL import Image# Create a horizontal grayscale gradient imagewidth, height = 256, 50image = Image.new("L", (width, height))for x in range(width):for y in range(height):image.putpixel((x, y), x)# Invert grayscale values using .point()inverted = image.point(lambda p: 255 - p)# Save the resultinverted.save("inverted-gradient.png")
The output for the example will be:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours