Skip to content

Add support for tags 50838 and 50839 in tif files #291

Closed

Description

@PhML

In some tif files saved by ImageJ, there is to tags unknown from TiffTags.py:
tag 50838 and 50839.

In the ImageJ source they are defined as:

    public static final int META_DATA_BYTE_COUNTS = 50838; // private tag registered with Adobe
    public static final int META_DATA = 50839; // private tag registered with Adobe

It also would be useful if we could save them.

Activity

  1. aclark4life commented on Jul 17, 2013

    @aclark4life
    Member

    Thanks, can you send a pull request?

  2. PhML commented on Jul 18, 2013

    @PhML
    Author

    It is just a question of adding them to TAGS dictionary in TiffTags.py (for what I understood). Should it be with tags below the comment "Adobe DNG" or we need to create another comment and if so, which one?

    My problem is also that I do not know about the saving part (see issue #290).

  3. wiredfool commented on Jul 18, 2013

    @wiredfool
    Member

    It looks like there's some need to add the tags that are preserved in the TiffImagePlugin save method: https://github.com/python-imaging/Pillow/blob/master/PIL/TiffImagePlugin.py#L923 . I'd have to check in more detail if there's some way that any tags not explicitly included are kept, but I don't think so. The default in other places in Pillow is to only include metadata that's explicitly specified.

    Do you have a redistributable test image that has the tags included?

  4. PhML commented on Aug 5, 2013

    @PhML
    Author

    Sorry about the delay, you can find an image here.
    You will also see that use of the show and getdata methods will give you errors as well scipy.fromimage. This might be the subject of a new issue.

  5. aclark4life commented on Sep 27, 2013

    @aclark4life
    Member

    @wiredfool Can this go in 2.2.0?

  6. cgohlke commented on Sep 27, 2013

    @cgohlke
    Contributor

    Even without adding names for the ImageJ tags, PIL allows to access all known and unknown tiff tags using their numbers in the tag or ifd attributes, e.g. img.tag[50838].

    I don't think it is a good idea to preserve software/application specific tags when saving in general and specifically not in this case.
    For example, the imagej tags in graphite1-1024.tif contain the following meta data:

    IMAGEJ_TAGS
    * ImageJ: 1.47t
    * info: root.ApplicationBounds = {0,0,1101,1920}
    * max: 1686.10949707
    * min: 852.08605957
    * unit: nm
    

    Processing the image (e.g. crop, re-sample, type conversion) with PIL and saving the metadata unchanged along with the processed image data will probably leave the file in an inconsistent or corrupt state.

  7. wiredfool commented on Sep 27, 2013

    @wiredfool
    Member

    It looks like tiffs with a mode of 'F;32BF' wasn't getting a proper mode/rawmode set to actually load the data.

    I'm guessing that there's actually a bunch of (potential) float 32 tiff modes that aren't properly loaded -- previously we interpreted F;32F (little endian floats) correctly, messed up F;32BF (big endian), and are totally missing the rest of the floats defined in Unpack.c, including 64 bit versions. Not that I'm convinced that any of the other ones show up in the wild, since the bug here is from the initial import into Pillow and we're only just finding it.

  8. wiredfool commented on Sep 28, 2013

    @wiredfool
    Member

    WRT to the tags, from https://github.com/python-imaging/Pillow/blob/master/PIL/TiffImagePlugin.py#L923

    It appears that we're only supporting writing certain tags into tiff files at all. The save process is essentially: Make a new tag directory, pull in some tags and encoder info, then write that. There's no option for adding any user generated stuff, explicitly or not.

    I'm looking at adding support for specific tags that users want to save, similar to how pnginfo is used on pings, but I'm running into type errors. Still digging on that.

  9. aclark4life commented on Sep 28, 2013

    @aclark4life
    Member

    OK feel free to punt this to 2.3.0 or Future if you need more time

  10. aclark4life commented on Oct 2, 2013

    @aclark4life
    Member

    If I understand correctly this is partially done and the rest can wait for 2.3.0

  11. wiredfool commented on Oct 2, 2013

    @wiredfool
    Member

    Yeah, it can wait.

  12. wiredfool commented on Oct 3, 2013

    @wiredfool
    Member

    I've added support in my tree for adding arbitrary tags to a tiff image by populating an ImageFileDirectory and sending that into the save method. Code is at https://github.com/wiredfool/Pillow/tree/tifftags . I'd like some more testing prior to actually merging this one, since I've done a good bit of mucking with the ImageFileDirectory internals. I may do even more, since there's a good bit of confusion between values and (type,value) tuples in the storage at this point.

    How to use: (alternately, checkout the test_file_tiff_metadata.py file)

    from PIL import Image, TiffImagePlugin
    
    img = Image.open('graphite1-1024.tif')
    
    info = TiffImagePlugin.ImageFileDirectory()
    info[50838] = img.tag.get(50838)
    info[50839] = img.tag.get(50839)
    
    img.save('tmp.tif',tiffinfo=info)
    
    tmp = Image.open('tmp.tif')
    print (tmp.tag.keys())
    print (tmp.tag[50839])
    print (tmp.tag[50838])
    
  13. aclark4life commented on Dec 28, 2013

    @aclark4life
    Member

    IIUC I just merged everything related to this issue

  14. added a commit that references this issue on Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions