Skip to content

[Term Entry] Python Pillow - Image: .point() #6518 #6533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c8f3a7
[Term entry] .point() #6518
TamorStewartSr Apr 11, 2025
70bfeb8
[Edit] .point() #6518
TamorStewartSr Apr 11, 2025
007c43f
[Edit] .point() #6518
TamorStewartSr Apr 12, 2025
6235351
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 12, 2025
b40cf88
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
0259240
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
1df97f1
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
c967671
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
8185b30
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
870a88d
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
77d4557
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
e8dfb4d
[Edit] .point() #6518
TamorStewartSr Apr 14, 2025
89a65da
Merge branch 'upstream/pillow-point-term' of https://github.com/Tamor…
TamorStewartSr Apr 14, 2025
6bcb4d9
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 14, 2025
caf304a
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 15, 2025
6ba47c5
Deleted the media folder
TamorStewartSr Apr 15, 2025
0df6d8c
Merge branch 'upstream/pillow-point-term' of https://github.com/Tamor…
TamorStewartSr Apr 15, 2025
dae523d
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 15, 2025
c9ac1cc
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 16, 2025
03eed29
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 17, 2025
d3cc0a4
Update point.md
mamtawardhani Apr 19, 2025
07fee36
Merge branch 'main' into upstream/pillow-point-term
mamtawardhani Apr 19, 2025
f18b286
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 19, 2025
b13bcd4
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 21, 2025
6b607d6
Merge branch 'main' into upstream/pillow-point-term
TamorStewartSr Apr 22, 2025
df784d6
Merge branch 'main' into upstream/pillow-point-term
Sriparno08 Apr 25, 2025
15d9e98
Minor changes
Sriparno08 Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions content/pillow/concepts/image/terms/point/point.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
Title: '.point()'
Description: 'Applies a function or lookup table to each pixel in an image.'
Subjects:
- 'Computer Science'
- 'Data Science'
Tags:
- 'Images'
- 'Pillow'
- 'Python'
CatalogContent:
- 'learn-python-3'
- 'paths/data-science'
---

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

```pseudo
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 argument `mode` 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:

```py
from PIL import Image

# Create a horizontal grayscale gradient image
width, height = 256, 50
image = 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 result
inverted.save("inverted-gradient.png")
```

The output for the example will be:

![A horizontal grayscale gradient image with inverted grayscale values](https://raw.githubusercontent.com/Codecademy/docs/main/media/inverted-gradient.png)
Binary file added media/inverted-gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.