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.
Asked
Active
Viewed 537 times
4
-
One of [these](http://effbot.org/zone/pil-extending.htm) in reverse may help. But you will still need to profile. – fraxel Apr 06 '12 at 14:19
-
This answer to a similar question http://stackoverflow.com/a/6539393/235698 might help you. – Mark Tolonen Apr 07 '12 at 07:09
2 Answers
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
-
I need to pass a PIL image to a third party image compressor written in C, so this really isn't an option for me. – Sam Washburn Apr 03 '12 at 17:19