.getdata()
Anonymous contributor
Published May 12, 2025
Contribute to Docs
The .getdata()
method in the Pillow library returns the pixel data of an image as a sequence. This allows in inspecting, manipulating, or analyzing the individual pixel values of an image, which is useful in image processing, filtering, or computer vision tasks.
Syntax
Image.getdata()
Parameters:
This method does not take any parameters.
Return value:
A sequence object containing pixel values of the image. The format depends on the image mode:
- In “RGB” mode: each pixel is a tuple like
(R, G, B)
. - In “L” (grayscale) mode: each pixel is a single integer representing light intensity.
- In “RGBA” mode: each pixel is a tuple like
(R, G, B, A)
.
Example
The image used in this example is as follows:
The example here opens an image, reads the pixel data using .getdata()
, and prints the first 10 pixel values:
# Import the Image module from the PIL libraryfrom PIL import Image# Load the imageimage = Image.open("pillow_getdata_sample.jpg")# Get pixel datapixels = image.getdata()# Print the first 10 pixelsprint(list(pixels)[:10])
The above code produces the following output:
[(245, 182, 176, 255), (244, 183, 177, 255), (245, 185, 179, 255), (244, 184, 179, 255), (244, 184, 178, 255), (244, 184, 178, 255), (244, 182, 178, 255), (243, 183, 176, 255), (243, 182, 175, 255), (243, 182, 177, 255)]
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
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 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