467,181 Members | 1,066 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,181 developers. It's quick & easy.

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

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 = Image.open("myFile.tif")
imgArray = numpy.zeros( ( img.size[0], img.size[1], numFrames ),
numpy.uint8 )
frame = 0
while 1:
img.seek( frame )
imgArray[:,:,frame] = img
frame = frame + 1
except EOFError:
img.seek( 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
  • viewed: 1130

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Curtis Justus | last post: by
3 posts views Thread by Al | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.