4

What is the most efficient way in terms of speed to access the pixel data of a PIL image from a C extension? I only need read-only access to it, if that makes a difference.

Sam Washburn
  • 1,760
  • 2
  • 21
  • 40

2 Answers2

0

C-level bindings for PIL are available, but there is very little documentation for them. You will need to consult the source for usage information.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
0

Besides C extension, you can try numpy. It takes a bit to learn though. To get started, check Convert RGBA PNG to RGB with PIL , and http://effbot.org/zone/pil-numpy.htm .

In my experience, numpy performance is great if the code is properly written. Processing image data can still be slow using C extension. But numpy uses SIMD instructions such as SSE2, which dramatically improves operation such as histogram elevating or alpha blending.

Community
  • 1
  • 1
He Shiming
  • 5,527
  • 4
  • 36
  • 64