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 arelooping over all of the pixels in an image, there is likelya faster way using other parts of the Pillow API.

Example

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

  1. from PIL import Image
  2. with Image.open('hopper.jpg') as im:
  3. px = im.load()
  4. print (px[4,4])
  5. px[4,4] = (0,0,0)
  6. print (px[4,4])

Results in the following:

  1. (23, 24, 68)
  2. (0, 0, 0)

Access using negative indexes is also possible.

  1. px[-1,-1] = (0,0,0)
  2. print (px[-1,-1])

PyAccess Class