[SciPy-dev] Patch for pilutils

Fernando Perez fperez at colorado.edu
Fri Oct 24 13:22:19 CDT 2003


Hi all,

here's a simple patch for pilutil which adds a simple 'flatten' option to the 
image reading functions imread.  Here are the resulting definition and docstrings:

In [2]: scipy.fromimage?
Definition:     scipy.fromimage(im, flatten=0)
Docstring:
     Takes a PIL image and returns a copy of the image in a Numeric container.
     If the image is RGB returns a 3-dimensional array:  arr[:,:,n] is each 
channel

     Optional arguments:

      - flatten (0): if true, the image is flattened by calling convert('F') on
      the image object before extracting the numerical data.  This flattens the
      color layers into a single grayscale layer.  Note that the supplied image
      object is NOT modified.


In [3]: scipy.imread?
Definition:     scipy.imread(name, flatten=0)
Docstring:
     Read an image file from a filename.

     Optional arguments:

      - flatten (0): if true, the image is flattened by calling convert('F') on
      the resulting image object.  This flattens the color layers into a single
      grayscale layer.


This is useful in case you want to load straight from an image file (jpeg, 
tiff, ...) but you want a single grayscale array to do numerics on.  The 
change is fully backwards compatible.  I did it because we needed here to 
easily read images for testing some numerical transformations without dealing 
with the color channels.  It was easier to patch scipy than to tell my 
coworkers to remember to convert every image first :)

Comments?

I think I can commit to CVS, but I don't want to without some feedback first 
on whether people like/dislike the idea.  Especially because it's not a 
bugfix, it's a new feature (albeit a small one).

Regards,

Fernando.

ps.  Hey Travis, thanks for committing the weave.catalog fix.  I was going to 
include that today in the patch and I checked the CVS, to find you'd done it.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pilutil.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20031024/bbe8741b/attachment.pl 


More information about the Scipy-dev mailing list