[Image-SIG] GeoTIFF?

Kevin.Cazabon@gretag.com Kevin.Cazabon@gretag.com
Thu, 15 Mar 2001 16:47:42 -0700


PIL can read the tag data in a TIFF file as follows:


if "a" is a TIFF image file that has JUST been opened, with no actions
performed on it, "a.tag.tags" is a dicitonary of tagnumber:value pairs
which can be assigned to or read.

So, if your tag is numbered "344", you simply call "a.tag.tags[344]" to get
the value.  You can also assign to this.
\
HOWEVER:  as soon as you perform any processing on "a", you lose all
TIFF-specific information... PIL does not remember that it "was" a TIFF
file, and therefore does not retain the TIFF tag dictionary.

I believe that you can simply make a copy of "a.tag" when you open the
file, and assign it back to the image just before saving, but I'm not 100%
sure off hand.  I know I've successfully done this to include the X and Y
resolution in the image file personally...

I added the following around line 567 of TiffImagePlugin to insert the
resolution data into the image during save:

    # HACK to let the user specify X and Y Resolution Tags for saving
    # simply create an im.RES or (im.XRES, im.YRES) attribute, with the
    # pixels per inch that you wish before saving
    #
    # alternatively, if your image was loaded from a TIFF file, it will
    # preserve the original PPI of the file unless you specify an im.RES,
    # im.XRES, or im.YRES value.
    # by Kevin Cazabon, Sept 2000 kcazabon@home.com
    if ("XRES" in dir(im) and "YRES" in dir(im)) or "RES" in dir(im):
        if "RES" in dir(im):
            ifd[282] = int(im.RES + 0.5)
            ifd[283] = int(im.RES + 0.5)
        if "XRES" in dir(im):
            ifd[282] = int(im.XRES + 0.5)
        if "YRES" in dir(im):
            ifd[283] = int(im.YRES + 0.5)

    elif "tag" in dir(im):  #meaning that it was loaded as a TIFF file
already
        if im.tag.tagdata.has_key(282):
            ifd[282] = im.tag.tagdata.get(282)
        if im.tag.tagdata.has_key(283):
            ifd[283] = im.tag.tagdata.get(283)



Kevin Cazabon
Product Manager, Software Applications and Systems
Gretag, Lab Systems Group

kevin.cazabon@gretag.com
303-754-0200 x289



                                                                                                                   
                    Russell                                                                                        
                    Nelson               To:     image-sig@python.org                                              
                    <nelson@crynw        cc:     (bcc: Kevin Cazabon/sienna/gig)                                   
                    r.com>               Subject:     [Image-SIG] GeoTIFF?                                         
                                                                                                                   
                    03/15/2001                                                                                     
                    04:21 PM                                                                                       
                                                                                                                   
                                                                                                                   





I need to read some proprietary TIFF tags out of a TIFF file (GeoTIFF
tags, which give the registration of the image relative to the
Universal Mercator Transform).  I see no obvious way to do this in the
source code?  I'm not on the mailing list; please cc me.

--
-russ nelson <sig@russnelson.com>  http://russnelson.com
Crynwr sells support for free software  | PGPok | Watch out!  He's got an
521 Pleasant Valley Rd. | +1 315 268 1925 voice | opinion, and he's not
Potsdam, NY 13676-3213  | +1 315 268 9201 FAX   | afraid to share it!

_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig