[Image-SIG] Image Problems
bbaxter at wadsworth.org
Thu Jan 19 16:13:51 CET 2006
I also had to write Python code to import a custom format into PIL, for
the SPIDER image processing system
(www.wadsworth.org/spider_doc/spider/docs/spider.html). Perhaps my
experience can give you some pointers.
First, remember that image processing is distinct from display. PIL can
apply operations to your data (change the grey-scale information), but
you'll need a graphical library, like Tkinter or wxPython, to create a
display GUI (e.g., view the slices by using a scroll button or the arrow
To import images into PIL, see "Writing Your Own File Decoder"
(www.pythonware.com/library/pil/handbook/decoder.htm). You'll write
something with a name like PurdueCATImagePlugin.py, which will go into
the python/site-packages/PIL directory, and import this, along with
Image, into Python. See the other xxxPlugin.py files in the PIL
directory for more examples.
To write your own Plugin.py, the first step is to know how the header
(if any) is structured so you can find where the data starts in the
file. Your data takes up 74973184 bytes (512x512x143x2). If this is the
size of the file, then there is no header, and you can try to read in
the raw data. If your file is larger than this, then the header should
be headerbytes = (filesize - 74973184) bytes. Try skipping headerbytes
into the file and reading the raw data. If it's anything more
complicated than this, then you'll need to get as much information as
you can from the CAT scanner documentation about its output format.
Empire State Plaza, PO Box 509
Albany, NY 12201-0509
Anne Davis wrote:
> Special Interest Group Members,
> I am a student at Purdue University. Myself and two other students are
> working on our senior design project and we have hit a snag when trying to
> import and view an image file. The file is a multi-slide picture from a CAT
> scan machine. For our project we need to be able to view the slides and
> also change the grey-scale information into a data range.
> We do know that the file type is not a built-in PIL format. We know the
> slide resolutions (512x512), there are 143 slides, the bytes per pixel (16
> bytes), the gap between slides (0 bytes), and that it's a 16 bit unsigned
> little endian format.
> Is there a way that we can get Python to import this file and be able to
> view the slices by using a scroll button or the arrow keys? Or should we be
> looking into another imaging program that already has this capability?
> Thanks for the time,
> Anne Davis
> Purdue University School of
> Nuclear Engineering
> davis87 at purdue.edu
> Image-SIG maillist - Image-SIG at python.org
More information about the Image-SIG