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
example code that iterates through the images in the 3-d tiff file
like this:

import Image
import numpy

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

and i have to get "numFrames" by initializing a counter to zero,
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
run this code versus analogous matlab code, the python version is
2 times slower (on average, 1.88 times slower when i time it with a
of different images). this may not seem like a lot, but when the
are frequently more than 1GB, it can add up.

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

any help/suggestions much appreciated...


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.