The Wayback Machine - https://web.archive.org/web/20240621181322/https://www.geeksforgeeks.org/python-pil-image-getdata/
Open In App

Python PIL | Image.getdata()

Last Updated : 02 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Previous Article
Next Article

Similar Reads

Convert OpenCV image to PIL image in Python
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a
3 min read
How to merge a transparent PNG image with another image using PIL?
This article discusses how to put a transparent PNG image with another image. This is a very common operation on images. It has a lot of different applications. For example, adding a watermark or logo on an image. To do this, we are using the PIL module in Python. In which we use some inbuilt methods and combine the images in such a way that it loo
2 min read
How to Convert PIL Image into pygame surface image?
In this article, we will know How to Convert PIL Image into pygame surface image. Pygame Surface Image: A surface that not only has fixed resolution and pixel format but also represents the image in Pygame is known as Pygame Surface Image. Are you constructing any game in Pygame in which you want to use only Pygame Surface Image as an input? As mos
4 min read
Python PIL | Image.crop() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image. Syntax: PIL.Image.crop(box = None)Parameters: box - a 4-tuple defining the left, upper, right, and lower pixel coordinate.Return type: Image (Returns a rectangular regio
2 min read
Adding Text on Image using Python - PIL
In Python to open an image, image editing, saving that image in different formats one additional library called Python Imaging Library (PIL). Using this PIL we can do so many operations on images like create a new Image, edit an existing image, rotate an image, etc. For adding text we have to follow the given approach. Approach Import moduleOpen ta
2 min read
Python PIL | Image.new() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each
2 min read
Python PIL | Image.split() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image. Splitting an “RGB” image creates three new images each containing a copy of one of the original bands (re
1 min read
Python PIL | Image filter with ImageFilter module
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. Image used: Filters - The current version of the library provides the set of predefined image enhancement filters: 1.
2 min read
Python PIL | Image.open() method
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. PIL.Image.open() Opens
2 min read
Python PIL | Image.point() method
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. Image.point() Maps this
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg