You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be a really handy feature if one could inspect the shape and dtype of file without having to load it into memory. This would be really handy with things like Dask that need to know this information in advance, but don't necessarily need to load the data until a computation happens.
Edit: Maybe this could be (or is) possible through the Readers.
The Reader has been designed to allow reading metadata without loading the image data (if the plugin implements it correctly). Your idea is quite similar to this, but it would need some sort of API (user-facing and plugin-facing). Or we could make plugins publish this kind of information via the meta-data.
Indeed, a convenience function such as read_meta that returns a dict, potentially with some standard fields, would be really useful in many contexts.
In the same vein as this issue, the TIFF metadata reader leaves much to be desired. In particular, if you look at the image I linked to in #226 [^1], opening it in Fiji yields a plethora of metadata (e.g. true volume dimensions), but virtually nothing in imageio, and only a bit better using TiffFile directly. @cgohlke might have more to say on the topic?
That sounds like a great idea. Let's come up with a set of fields (starting with shape, dtype, nchannels) that plugins are recommended to publish via their meta data.
The most critical after those is "spacing" for pixel/voxel spacing, along with "units" for the units of the rest of the metadata. @shoyer probably has another 50 fields to suggest. =D
Incidentally, I think these standard fields should be returned in addition to whatever fields are in the format. Readers could then translate between the Reader's format and the standard format. But ideally, all the information in the file should be accessible from iio.
Incidentally, I think these standard fields should be returned in addition to whatever fields are in the format.
I agree. We'd have to think about name clashes too. Perhaps by separating the two, e.g. by having a native field in the metadata, which is a dict with fields specific to the format.
Would recommend thinking about passing axes as well to specify axis ordering (especially if nchannels is considered). For instance if you look at the example, the axes are XYCZT. This is in the TIFF metadata or can also be found via the info in Fiji/ImageJ. Though letting this fall through in miscellaneous metadata might be ok too.
It's not atypical to have all sorts of orderings of the axes and it can be a bit of a guessing game to figure out which is which. So any info passed along that might help is really great.
opening it in Fiji yields a plethora of metadata (e.g. true volume dimensions), but virtually nothing in imageio, and only a bit better using TiffFile directly
I think it's all there but the info string needs to be converted to a dict:
dtype and shape are the most essential ones. An explicit __array__ method is also valuable for numpy compatibility. ndim and size are easy enough to add as well, defined based on shape.
It looks like the info string in the ImageJ metadata can be of many (undocumented) formats and can not be reliably be parsed in general. In the case of E_z2_512_1um_CONTROL.tif, the info string seems to contain metadata from an OIF file. I found other files where the info string contains a string representation of a Matlab struct. You might or might not be able to parse the info strings with oiffile.SettingsFile() or matlabstr2py().
I think ImageJ uses the x_resolution, y_resolution, resolution_unit, and image_description (the spacing and unit entries) TIFF tags of the first TIFF page to determine the pixel spacing. See blink1073/tifffile#15 (comment)
While it may be hard to parse general metadata, the basics asked for in the description (shape and dtype) may be feasible to implement already? EDIT: Looks like it is already available, and we just need an additional high-level API to expose it?
Something like imread.header(image) could return whatever it can discover about the image as a dictionary with known fields. Whatever isn't there then becomes the consumer's responsibility to handle.
Activity
almarklein commentedon Jun 7, 2017
The
Readerhas been designed to allow reading metadata without loading the image data (if the plugin implements it correctly). Your idea is quite similar to this, but it would need some sort of API (user-facing and plugin-facing). Or we could make plugins publish this kind of information via the meta-data.jni commentedon Jun 7, 2017
Indeed, a convenience function such as
read_metathat returns a dict, potentially with some standard fields, would be really useful in many contexts.In the same vein as this issue, the TIFF metadata reader leaves much to be desired. In particular, if you look at the image I linked to in #226 [^1], opening it in Fiji yields a plethora of metadata (e.g. true volume dimensions), but virtually nothing in imageio, and only a bit better using TiffFile directly. @cgohlke might have more to say on the topic?
[1] https://www.dropbox.com/s/dj3oarx7bqx4us2/E_z2_512_1um_CONTROL.tif?dl=1 (Updated)
almarklein commentedon Jun 7, 2017
That sounds like a great idea. Let's come up with a set of fields (starting with
shape,dtype,nchannels) that plugins are recommended to publish via their meta data.jni commentedon Jun 7, 2017
The most critical after those is "spacing" for pixel/voxel spacing, along with "units" for the units of the rest of the metadata. @shoyer probably has another 50 fields to suggest. =D
Incidentally, I think these standard fields should be returned in addition to whatever fields are in the format. Readers could then translate between the Reader's format and the standard format. But ideally, all the information in the file should be accessible from iio.
almarklein commentedon Jun 7, 2017
I agree. We'd have to think about name clashes too. Perhaps by separating the two, e.g. by having a
nativefield in the metadata, which is a dict with fields specific to the format.jni commentedon Jun 7, 2017
👍 !
jni commentedon Jun 7, 2017
Oops! Sorry:
https://www.dropbox.com/s/dj3oarx7bqx4us2/E_z2_512_1um_CONTROL.tif?dl=1
Will update link above also.
jakirkham commentedon Jun 7, 2017
Would recommend thinking about passing
axesas well to specify axis ordering (especially ifnchannelsis considered). For instance if you look at the example, the axes areXYCZT. This is in the TIFF metadata or can also be found via the info in Fiji/ImageJ. Though letting this fall through in miscellaneous metadata might be ok too.It's not atypical to have all sorts of orderings of the axes and it can be a bit of a guessing game to figure out which is which. So any info passed along that might help is really great.
jni commentedon Jun 7, 2017
... Which, in NumPy order, turns to TZCYX. This should be a fun project. =P
cgohlke commentedon Jun 7, 2017
I think it's all there but the
infostring needs to be converted to a dict:shoyer commentedon Jun 7, 2017
As a point of reference, here are attribute we define for numpy-like array types used internally in xarray:
https://github.com/pydata/xarray/blob/e39dae4c4ba83de09bea16ed5b3132ce4e88ba98/xarray/core/utils.py#L381-\L425
dtypeandshapeare the most essential ones. An explicit__array__method is also valuable for numpy compatibility.ndimandsizeare easy enough to add as well, defined based onshape.cgohlke commentedon Jun 7, 2017
It looks like the
infostring in the ImageJ metadata can be of many (undocumented) formats and can not be reliably be parsed in general. In the case of E_z2_512_1um_CONTROL.tif, the info string seems to contain metadata from an OIF file. I found other files where the info string contains a string representation of a Matlab struct. You might or might not be able to parse the info strings with oiffile.SettingsFile() or matlabstr2py().jni commentedon Jun 7, 2017
I was afraid of this @cgohlke. Do you know whether ImageJ is using that info string or something else to pull out the pixel spacing?
cgohlke commentedon Jun 8, 2017
I think ImageJ uses the
x_resolution,y_resolution,resolution_unit, andimage_description(thespacingandunitentries) TIFF tags of the first TIFF page to determine the pixel spacing. See blink1073/tifffile#15 (comment)stefanv commentedon May 29, 2018
While it may be hard to parse general metadata, the basics asked for in the description (shape and dtype) may be feasible to implement already? EDIT: Looks like it is already available, and we just need an additional high-level API to expose it?
almarklein commentedon May 30, 2018
That depend on the plugin. I think this is the case for the Pillow plugin, but not necessarily for any of the others ...
jakirkham commentedon May 30, 2018
Think this should also be possible with
tifffileas well.stefanv commentedon May 30, 2018
Something like
imread.header(image)could return whatever it can discover about the image as a dictionary with known fields. Whatever isn't there then becomes the consumer's responsibility to handle.almarklein commentedon May 30, 2018
Actually, we already have
Reader.get_meta_data(https://github.com/imageio/imageio/blob/master/imageio/core/format.py#L364), but its implementation/test coverage is not very complete. E.g.I propose that we:
(As for when/who: I probably don't have time to work on this before the summer myself.)
almarklein commentedon Sep 11, 2018
Closing this in favor of #382, where we propose/discuss a specific solution for this use-case.