[Image-SIG] reading multi-frame tiff images?

W. Bryan Smith wbsmith at gmail.com
Fri May 18 21:38:23 CEST 2007


hi,

i am wondering if there is a faster way to find the number of frames or pages
in a 3-d tiff image than doing something like this:

img = Image.open("myFile.tif")
frame = 0
try:
    while 1:
        img.seek(frame)
        frame = frame + 1
except EOFError:
    img.seek(0)
    pass


any hints on this?  i looked through all the tags and did not find anything that
tells the number of frames in the 3-d tiff images i am working with.  this code
works, but seems to be somewhat slow.  also, along these lines, i wonder if
there is generally any faster way to read these multi-frame tiff images than
what i list above (assuming i also then assign img to some 3-d array i made
using numpy).  doing so with my images can take up to twice as long as if i
read the same images in matlab (an average of 1.88 times slower when i test
with a bunch of different images).  even as compared to my matlab code, the
actual read time is not prohibitively slow, but is considerably slower than any
other means i have of reading the images, so i am guessing there must be a
better way for me to read the data than this try: statement.

thanks for any insight!

bryan


More information about the Image-SIG mailing list