By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

reading 3-d (multi-page) tiff images with python/pil

P: n/a
hello all,

i am using python (2.5) with the PIL (latest [last?] release), and i
am trying
to read in these 3-d tiff images we have. basically, i am following
some
example code that iterates through the images in the 3-d tiff file
like this:

import Image
import numpy

img = Image.open("myFile.tif")
imgArray = numpy.zeros( ( img.size[0], img.size[1], numFrames ),
numpy.uint8 )
frame = 0
try:
while 1:
img.seek( frame )
imgArray[:,:,frame] = img
frame = frame + 1
except EOFError:
img.seek( 0 )
pass

and i have to get "numFrames" by initializing a counter to zero,
looping
through the same "seek" statement, and returning the counter once EOF
has been reached.

two questions:
1) is there a faster way to do this? when i compare the time required
to
run this code versus analogous matlab code, the python version is
about
2 times slower (on average, 1.88 times slower when i time it with a
bunch
of different images). this may not seem like a lot, but when the
images
are frequently more than 1GB, it can add up.

2) is there a better way to get the numFrames (or to combine getting
the
numFrames with the rest of the code) so that i do not have to iterate
over
the seek() function twice?

any help/suggestions much appreciated...

thanks,
bryan

May 22 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.