[Image-SIG] saving tiffs

Scott Rifkin scott.rifkin at yale.edu
Tue Jul 6 17:46:21 CEST 2004

I have a multi-image tiff with 4 frames where the first 2 are jpeg 
previews and the last two are 16 bit tiffs.

I want to adjust some of the pixel values in the tiffs and then save the 
result (either to single image 16 bit tiffs or to a multi-image tiff.  i 
don't need the jpegs).

here is what i tried (for one of the single-image tiffs):

    im = Image.open(directory +array_ID + '_MUL.tif')
    cy5 = im
    for i in range (len( columns)):
        for pixelx in range (int (columns [i])-maximum_diameter/3, int (columns [i])+maximum_diameter/3):
            for pixely in range (int (rows [i])-maximum_diameter/3,int (rows [i]) + maximum_diameter/3):
                cy5.putpixel((pixely, pixelx),50000)
    cy5.save(directory +array_ID + '_635.tif',im.format)

the for loop just adds a square of pixels with value 50000

this is the error i get:

  File "/usr/local/lib/python2.3/site-packages/PIL/Image.py", line 1136, in save
    SAVE[string.upper(format)](self, fp, filename)
  File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 677, in _save
    offset = ifd.save(fp)
  File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 356, in save
    data = string.join(map(o32, value), "")
  File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 55, in ol32
    return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255)
TypeError: unsupported operand type(s) for &: 'str' and 'int'

thanks for any help and any suggestions if there is a better way to do 

scott rifkin
scott rifkin at yale dot edu

More information about the Image-SIG mailing list