Reading meta data only from microscopy data .tif-files in python

Hello everyone,

I am getting started with image analysis in python and have issues importing the metadata from microscopy data .tif-files that I hope you might be able to help with.

The data I am looking at might consist of bigger stacks, so ideally I would like to import the meta data before opening the desired part of the image only.

In principle, this can be done using the SimpleITK ImageFileReader, setting it up and then using GetMetaDataKeys() for reading the meta data and creating calling the ImageFileReader a second time to extract the desired part of the image after setting the constraints. But I run into the following issues:

  1. Most of the meta data is returned as one long string that belongs to a single key. (Currently, I am creating a dictionary from by ‘manually’ splitting this string.)

  2. Some of the meta data keys can’t be accessed at all in this way. In these cases the GetMetaData() function returns the default string ‘[UNKNOWN_PRINT_CHARACTERISTICS]’. However, the meta data can be accessed in Fiji and matlab.

  3. The 5D data is only interpreted as 3D by the ImageFileReader. The skimage.io.imread() function however manages to interpret the data correctly as 5D (but can’t be used to import a fraction of the data only). This problem is a little less relevant than the first two, but to me it seems that this is caused by the issue of not reading and interpreting the meta data properly.

Some more information: I am using python version 3.7(.4), SimpleITK version 1.2rc1, the data I am processing consists of 5D stacks (3 spatial dimensions, time, channel). I only want to read .tif files, but the metadata is stored using different conventions.
If you need more info, please let me know.

I am hope some of you can help with this. ( @Christian_Tischer thank you for sending this to people who may be able to.)

Best and thanks,
Jana

1 Like

@joshmoore, can you help?

1 Like

Maybe this helps?

2 Likes

This does not work right away, but after converting my .tif file to ome.tiff using ImageJ, this works nicely! Thank you Sebi.

1 Like

This does not work with my metadata (the part that I could not access before still can’t be opened), but it works even for ome.tiff. I will combine it with Sebi’s response for reading in the data in parts and then all of my problems are solved. Thanks a million!

2 Likes

Hey,
I found a minor mistake in lines 642/643 and I am not allowed to send private messages yet. It should be c=c_ind in:
def get_TZC_czi(t_ind, c_ind, z_ind, r):
display_image(array, metadata, sliders, t=t_ind, c=t_ind, z=z_ind, vmin=r[0], vmax=r[1])

2 Likes

Looks like I missed the fun, but it does remind me of this discussion with @sebi06 that we might want to come back to.

All the best, ~Josh