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,817
  • 3
  • 25
  • 43

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
  • 776,304
  • 153
  • 1,341
  • 1,358
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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
He Shiming
  • 5,710
  • 5
  • 38
  • 68