[Image-SIG] Obtaining image data in numarray

Andrew Straw andrew.straw at adelaide.edu.au
Mon Jul 14 16:09:04 EDT 2003


On Thursday, July 10, 2003, at 09:29  PM, Chuck Bass wrote:

> I need to look at the image data in an array form (ideally using
> numarray).  With PIL I could loop over the data and stuff x,y's into a
> numarray but the speed would be glacial large images.

I'm not the expert, but seeing as no one better qualified has answered:

I don't think C coding is needed, even for decent speed.  Here's Python 
code for Numeric, and I assume there must be something extremely 
similar for numarray.  There are also a number of similar recipes 
floating around.

import Numeric
import Image

def pil2numpy(im):
     if im.mode != 'RGB':
         raise ValueError("Expecting RGB image")

     width, height = im.size

     im_n = Numeric.fromstring( im.tostring('raw','RGB',0,-1), 
Numeric.UnsignedInt8 )
     im_n = Numeric.reshape( im_n, (height,width,3) )
     return im_n




More information about the Image-SIG mailing list