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

W

wbsmith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top