From: Johannes L. <a.u...@gm...> - 2006-08-30 18:11:11
|
Am Mittwoch, 30. August 2006 19:20 schrieb Ghalib Suleiman: > I'm somewhat new to both libraries...is there any way to create a 2D > array of pixel values from an image object from the Python Image > Library? I'd like to do some arithmetic on the values. Yes. To transport the data: >>> import numpy >>> image = <some PIL image> >>> arr = numpy.fromstring(image.tostring(), dtype=numpy.uint8) (alternately use dtype=numpy.uint32 if you want RGBA packed in one number). arr will be a 1d array with length (height * width * b(ytes)pp). Use reshape to get it into a reasonable form. HTH, Johannes |