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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wbsmith@gmail.com

    #1

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

    import Image
    import numpy

    img = Image.open("myF ile.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

Working...