[Image-SIG] Use of FFT with PIL objects??

Bob Klimek robert.klimek@grc.nasa.gov
Thu, 20 Apr 2000 13:53:53 -0400


Jeff Nash wrote:
> 
> I'm intend to use PIL to view and manipulate images. My question is how to
> use 2D FFT techniques on the image objects created by, e.g. im =
> Image.open("imagefile.psd") ??
> 
> It would be very convenient to use the FFT routines implemented in the
> Numeric package.  I expect I'd have to create a 2D 'array' object from
> 'im', unless by great good fortune the Numeric package is already familiar
> with Image objects (unlikely I'd guess).  That suggests I'd need to extract
> the data from the image object.
> 
> Any good suggestions on how to proceed here?  If anyone has a different way
> to accomplish this I'd be very interested.
> 
Jeff,

I don't know for sure since I've never done it but from what I know of
Numeric Python (NumPy), it should be fairly easy. Since I doubt that
NumPy understands PIL image format, you'll have to convert the image to
a linear array of integers and then read it into NumPy. To convert PIL
image to a list of integers, do:

d = img.getdata()

and then read "d" into NumPy using array call. Convert it to a 2-d
array. For color images you'll probably have to split the image into
r,g,b planes first.

Bob
-- 
---------------------
Robert B. Klimek
NASA Glenn Research Center
robert.klimek@grc.nasa.gov
---------------------