PyAccess Module

The PyAccess module provides a CFFI/Python implementation of the PixelAccess Class. This implementation is far faster on PyPy than the PixelAccess version.

Note

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.

Example

The following script loads an image, accesses one pixel from it, then changes it.

from PIL import Image
im = Image.open('hopper.jpg')
px = im.load()
print (px[4,4])
px[4,4] = (0,0,0)
print (px[4,4])

Results in the following:

(23, 24, 68)
(0, 0, 0)

PyAccess Class

class PIL.PyAccess.PyAccess[source]
getpixel(xy)

Returns the pixel at x,y. The pixel is returned as a single value for single band images or a tuple for multiple band images

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.
putpixel(xy, color)

Modifies the pixel at x,y. The color is given as a single numerical value for single band images, and a tuple for multi-band images

Parameters:
  • xy – The pixel coordinate, given as (x, y).
  • value – The pixel value.

Table Of Contents

This Page

Need help?

You can get help via IRC at irc://irc.freenode.net#pil or Stack Overflow here and here. Please report issues on GitHub.