Random Projects: Numeric <--> PIL Module

These are a few random projects. They range from very useful to totally frivolous. Consider them all to be under the GPL.


This script describes the NumPil Python Module.  It is distributed 
under the GPL.  Have fun.

Brian Hone 3/24/2002

Overview:
=========

This python module is a translator for PIL and Numeric.  

It can be used to load an image into a Numeric array, 
or load a numeric array as a PIL image.

Implementation:
===============

Black and White -- All images are treated as 8 bit Greyscale.
Color - All image are treated as 8 bit RGB.

Code:
=====

Here's some example code:

import numpil

a = numpil.numpil()
b = numpil.numpil()

# load an image using PIL (into a.img)
a.loadImage('gs.jpg')
# create a Numeric object (into a.numHandle)
a.greyToNumeric()
# copy that Numeric object into b.numHandle
b.numHandle = a.numHandle
# create a PIL object (into b.img)
b.numToGrey()
b.img.save('foo.bmp')

# do the same thing with a color image
a.loadImage('/Users/bhone/foo.jpg')
a.colToNumeric()
b.numHandle = a.numHandle
b.numToCol()
b.img.save('foo.bmp')

ToDo:
=====
Do more with various bit-depths.  This way works, but doesn't
uses extra space for lower resolution.

 
 
numpil (version 0.1, Mar 23, 2002)
index
/Library/WebServer/Documents/projects/NumPil/numpil.py

 
Modules
            
Image
Numeric
os
sys
time
 
Classes
            
numpil
 
class numpil
      This module is a wrapper which allows one to transfer objects from PIL to Numeric and back.
 
   Methods defined here:
__init__(self)
assembleColors(self)
combine 3 matricies(r,g, and b) into rgbrgbrgb...
colToNumeric(self)
Converts an image to RGB, and then Loads the colors up into Numeric
greyToNumeric(self)
Converts an image to Greyscale, and the Greyscale image to Numeric
loadImage(self, imagePath)
Open an Image using PIL, find out its useful information
numToCol(self)
Convert a Numeric x*y array to a greyscale PIL image
numToGrey(self)
Convert a Numeric x*y array to a greyscale PIL image

Data and non-method functions defined here:
__doc__ = '\n\tThis module is a wrapper which allows one t...ansfer objects from PIL to Numeric and back.\n\t'
__module__ = 'numpil'
 
Functions
            
toNum(inIMG, x, y)
convert a PIL string to Numeric Array
Load the image in as a string, reshape it to a matrix, then transpose it for use with Numeric, then cut it down to size
 
Data
             __author__ = 'Brian Hone'
__date__ = 'Mar 23, 2002'
__email__ = 'bhone@eink.com'
__file__ = './numpil.pyc'
__name__ = 'numpil'
__version__ = '0.1'
 
Author
             Brian Hone