Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PhML opened this issue Jul 17, 2013 · 13 comments
Closed

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

PhML opened this issue Jul 17, 2013 · 13 comments

Comments

@PhML
Copy link

PhML commented Jul 17, 2013

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.

@aclark4life
Copy link
Member

Thanks, can you send a pull request?

@PhML
Copy link
Author

PhML commented Jul 18, 2013

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).

@wiredfool
Copy link
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?

@PhML
Copy link
Author

PhML commented Aug 5, 2013

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.

@aclark4life
Copy link
Member

@wiredfool Can this go in 2.2.0?

@cgohlke
Copy link
Contributor

cgohlke commented Sep 27, 2013

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.

@wiredfool
Copy link
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.

@wiredfool
Copy link
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.

@aclark4life
Copy link
Member

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

@wiredfool wiredfool mentioned this issue Sep 28, 2013
2 tasks
@aclark4life
Copy link
Member

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

@wiredfool
Copy link
Member

Yeah, it can wait.

@wiredfool
Copy link
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])

@aclark4life
Copy link
Member

IIUC I just merged everything related to this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants