Thursday, June 18, 2026
HomeLanguagesPython PIL | Image.getdata()

Python PIL | Image.getdata()

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.

getdata() Returns the contents of this image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on.

Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations. To convert it to an ordinary sequence (e.g. for printing), use list(im.getdata()).

Syntax: Image.getdata(band=None)

Parameters:

band – What band to return. The default is to return all bands. To return a single band, pass in the index value (e.g. 0 to get the “R” band from an “RGB” image).

Returns type: A sequence-like object.

Image Used:




   
  
# importing Image module from PIL package 
from PIL import Image 
   
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\lion.png").convert("L"
   
# getting colors 
# multiband images (RBG) 
im1 = Image.Image.getdata(im) 
   
print(im1) 


Output:

ImagingCore object at 0x0000026E11CD52D0

Another example:Here we change image.
Image Used




# importing Image module from PIL package 
from PIL import Image 
   
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\tree.jpg").convert("L"
   
# getting colors 
# multiband images (RBG) 
im1 = Image.Image.getdata(im) 
   
print(im1) 


Output:

ImagingCore object at 0x0000029BA596C230
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS