Skip to content

option to read tiff metadata - #1995

Closed
jenniferdai1 wants to merge 2 commits into
scikit-image:masterfrom
jenniferdai1:tiff_read_metadata
Closed

jenniferdai1 wants to merge 2 commits into
scikit-image:masterfrom
jenniferdai1:tiff_read_metadata

Conversation

@jenniferdai1

Copy link
Copy Markdown

addressing issue #1940
Automatic inversion of binary image stored as TIFFILE

created imread_metadata, imread_with_metadata, and imread(include_metadata = False) methods in tifffile_plugin.py, as suggested in a comment in the issue thread

added a new method, asarray_with_metadata, in tifffile.py that returns the image array along with a list of metadata dictionaries for each page.
Returns metadata dictionary for first page by default, like how tifffile returns the first image series by default.

@stefanv

stefanv commented Mar 9, 2016

Copy link
Copy Markdown
Member

Let's do:

imread : image only
imread_metadata : image + metadata

Additional keyword arguments to pass through (see ``tifffile``'s
``imread`` function).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up whitespace here and above

@jenniferdai1

Copy link
Copy Markdown
Author

Sorry, could you explain what you mean by "separate" metadata reader? I was trying to follow your suggestion in the comment thread ("Some options:.....")

Thank you for your input!

@jni

jni commented Mar 10, 2016

Copy link
Copy Markdown
Member

Hi Jennifer! First of all, thanks for tackling this, I'll be very happy to see it resolved!

Secondly, what I meant was, write a (potentially private) function that reads only metadata, and then say:

def imread_metadata(filename):
    return imread(filename), _metadata(filename)

I think that would be cleaner than expanding the imread function itself.

Thirdly, although I agree with @stefanv that we should limit the number of options (from the Zen of Python: "There should be one-- and preferably only one --obvious way to do it."), I don't agree with the best choice here, and my preference would be imread(filename, (return_|with_)metadata=False). This is not a strong opinion but rather a gut preference. The downside is the changing function signature depending on input, but it's a common enough pattern in SciPy that I don't think it's a big problem. Let's wait for a counterpoint from @stefanv about this before you keep cranking on this...

And finally, thanks for including a good test from the get-go, but I would like to specifically make sure that the case that started this (inverted values) works, so could you add:

  • a test image for that use case, and
  • a test of multipage metadata.

Thank you!

@stefanv

stefanv commented Mar 10, 2016

Copy link
Copy Markdown
Member

@jni If we add the "metadata=False/True" flag, then I think we should not have imread_metadata implemented. For me, it's one or the other. I'm not a big fan of functions that use a flag to change the type of output they provide, hence my preference for imread_metadata, but I wouldn't argue too much either way.

@jni

jni commented Mar 10, 2016

Copy link
Copy Markdown
Member

@stefanv I agree that it's one or the other, and I also have only a small bias towards the kwarg. For me, it just seems more natural that this would be part of the imread function rather than a separate function, and I like to keep my tab-completion clean. =) Perhaps we can just have a vote? @emmanuelle @JDWarner @ahojnnes @blink1073 ?

For context, we are trying to decide whether to return image metadata using a separate function (imread_metadata, returning both the image and the metadata), or using a keyword argument to imread, so that it would optionally return metadata as well as the image, based on the value of the metadata=True/False kwarg.

Actually, I just thought of another argument in favour of the kwarg: the option to read metadata should probably generalise to imread_collection. That's easier with a kwarg.

@soupault soupault added the ⏩ type: Enhancement Improve existing features label Mar 10, 2016
@blink1073

Copy link
Copy Markdown
Contributor

I prefer the approach taking by imageio:

"Reads an image from the specified file. Returns a numpy array, which comes with a dict of meta data at its ‘meta’ attribute."

http://imageio.readthedocs.org/en/latest/userapi.html#imageio.imread

@jni

jni commented Mar 10, 2016

Copy link
Copy Markdown
Member

@blink1073 I like that idea! It actually crossed my mind but then I was like nooooo, are we even allowed to do that??? =P

@stefanv

stefanv commented Mar 10, 2016 via email

Copy link
Copy Markdown
Member

@jni

jni commented Mar 10, 2016

Copy link
Copy Markdown
Member

@stefanv very good point — super easy to lose the metadata when it's in some undocumented extra field.

@emmanuelle

Copy link
Copy Markdown
Member

+1 for sticking with standard structures :-). I'd slightly prefer the separate function, but I don't have a strong dislike of the kw argument either.

Comment thread skimage/io/_io.py
Passed to the given plugin.

"""
# Backward compatibility

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is backward compatibility needed for a completely new function too ?

@AbdealiLoKo

Copy link
Copy Markdown
Contributor

So, I notice that the tag attribute from tifffile is directly given out.
Wouldn't it be better to curate the list of metadata that's being shown ? This way it can be standardized for other plugins too. Otherwise, the user will have to read the doumentation of each backend individually and also decipher which backend was used in the file to be able to use the metadata (as otherwise the keys will change).

The metadata that is exposed by the function can be added based on requirement, otherwise skimage which s an image processing toolkit would be bogged down by exif/meta data reading.

Also, the tiff tags mentioned at tiff tags have: Comments, Model (The model of the scanner), Artist, TargetPrinter, XMP, BatteryLevel, Copyright, ICCProfile, GPSInfo, and a whole lot of information that an image processing toolkit wouldn't care about. This seems like unnecessary noise. To read that sort of meta-information, the user should actually use an exif/meta reader like exiftool, gexiv2, etc.

@stefanv

stefanv commented Feb 17, 2017

Copy link
Copy Markdown
Member

@AbdealiJK Agreed that we should have a set of standard meta-data, and then perhaps a custom or raw entry that contains everything the reader can provide.

@stefanv

stefanv commented Jul 15, 2017

Copy link
Copy Markdown
Member

See #2709

@stefanv stefanv closed this Jul 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants