Re: [Image-SIG] Obtaining image data in numarray
by Andrew Straw other posts by this author
Jul 14 2003 1:09PM messages near this date
[Image-SIG] Obtaining image data in numarray
|
[Image-SIG] obtaining palette data
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
_______________________________________________
Image-SIG maillist - Image-SIG@[...].org
http://mail.python.org/mailman/listinfo/image-sig
Thread:
Chuck Bass
Andrew Straw
|