PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The PixelAccess class provides read and write access to PIL.Image data at a pixel level.
Accessing individual pixels is fairly slow. If you are looping over all of the pixels in an image, there is likely a faster way using other parts of the Pillow API.
getpixel() Returns the pixel at x, y. The pixel is returned as a single
Syntax: getpixel(self, xy)
Parameters:
xy :The pixel coordinate, given as (x, y).
Returns: a pixel value for single band images, a tuple of pixel values for multiband images.
Image Used:

# Importing Image from PIL package from PIL import Image # creating a image object im = Image.open(r"C:\Users\System-Pc\Desktop\leave.jpg") px = im.load() print (px[4, 4]) px[4, 4] = (0, 0, 0) print (px[4, 4]) cordinate = x, y = 150, 59 # using getpixel method print (im.getpixel(cordinate)); |
Output:
(130, 105, 49) (0, 0, 0) (75, 19, 0)
Another example:Here we change the cordinate value.
Image Used

# Importing Image from PIL package from PIL import Image # creating a image object im = Image.open(r"C:\Users\System-Pc\Desktop\leave.jpg") px = im.load() print (px[4, 4]) px[4, 4] = (0, 0, 0) print (px[4, 4]) cordinate = x, y = 180, 79 # using getpixel method print (im.getpixel(cordinate)); |
Output:
(130, 105, 49) (0, 0, 0) (22, 168, 25)
Recommended Posts:
- Python PIL | GaussianBlur() method
- Python PIL | ImageDraw.Draw.pieslice()
- Python PIL | Kernel() method
- Python PIL | BoxBlur() method
- Python PIL | logical_and() and logical_or() method
- Python PIL | ImageChops.subtract() method
- Python PIL | UnsahrpMask() method
- Python PIL | ImageOps.expand() method
- Python PIL | MedianFilter() and ModeFilter() method
- Python PIL | logical_xor() and invert() method
- Python PIL | ImageOps.equalize() method
- Python | ImageOps.autocontrast()method
- Python PIL | ImageOps.fit() method
- Python | PIL Attributes
- Python PIL | ImageOps.postarize() method
- Python PIL | ImageOps.greyscale() method
- Python PIL | ImageOps.flip() method
- Python PIL | ImageOps.solarize() method
- Python PIL | ImageChops.duplicate()
- Python PIL | eval() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

