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

can not parse positions from ome-tiff generated by micro-manager #54

Closed
bryantChhun opened this issue Jan 14, 2021 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@bryantChhun
Copy link

Following up on the discussion at image.sc here, I'd like to provide a little more detail about what I see when trying to load the ome-tiffs:

if the dimensionality and folder structure is as such:
(T, P, Z, C, Y, X) = (50, 2, 5, 3, 2048, 2048)
image

The resulting array from running:

>>> a = tifffile.imread('/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos000_000.ome.tif')
>>> a.shape
>>> (50, 5, 3, 2048, 2048)

This is ok if it means that I can simply load the other series/positions and get a similar shape, however:

>>> b = tifffile.imread('/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos001_000.ome.tif')
>>> b.shape
>>> (510, 2048, 2048)

which is only a partial load of that series -- it should at least be (750, 2048, 2048)

From pypi notes:

OME-TIFF stores up to 8-dimensional data in one or multiple TIFF of BigTIFF files.

So ideally we can get an array like (T, P, Z, C, Y, X) = (50, 2, 5, 3, 2048, 2048)

@cgohlke
Copy link
Owner

cgohlke commented Jan 14, 2021

a = tifffile.imread('/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos000_000.ome.tif')
b = tifffile.imread('/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos001_000.ome.tif')

I do not have access to those exact files and cannot comment on the partial loading issue.

This is ok if it means that I can simply load the other series/positions

This is by design and agrees with how Bio-Formats imports those images into Fiji. Series may have different data types, shapes, etc and cannot in general be accessed as a single numpy or zarr array. Maybe in the future the OME-ZARR will handle these cases.

OME-TIFF stores up to 8-dimensional data in one or multiple TIFF of BigTIFF files.
So ideally we can get an array like (T, P, Z, C, Y, X) = (50, 2, 5, 3, 2048, 2048)

OME does only support a very limited number, order, and kind of image dimensions. Position is not one of them. Hence positions are saved as separate series.

Re OME series: not an ome-tiff master file:

This means the file does not contain the complete OME-XML metadata and tifffile is unable to find the master OME-TIFF file containing the complete metadata. Your OME-TIFF files created by MicroManager also contains a second ImageDescription tag with ImageJ metadata. Tifffile does not look for ImageJ metadata in the second ImageDescription tag in this case. This could be fixed.

@bryantChhun
Copy link
Author

bryantChhun commented Jan 14, 2021

This means the file does not contain the complete OME-XML metadata and tifffile is unable to find the master OME-TIFF file containing the complete metadata. Your OME-TIFF files created by MicroManager also contains a second ImageDescription tag with ImageJ metadata. Tifffile does not look for ImageJ metadata in the second ImageDescription tag in this case. This could be fixed.

This might explain why ImageJ can identify the positions/scenes and allow them to be loaded. In the meantime, is there a workaround to enable manual loading of the other series?

# this is the master OME-tiff
'/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos000_000.ome.tif'  

# this is the 2nd position/series whose metadata is in the above file
'/image_stack_tpzc_50tp_2p_5z_3c_2k_1_MMStack_2-Pos001_000.ome.tif'  

Edit:
I discovered that i can simply pass the series=# flag to aszarr or asarray. This seems to work fine so far!

@cgohlke
Copy link
Owner

cgohlke commented Jan 15, 2021

I'm closing this. The numpy/zarr array shape for a particular series is correct. tifffile v2021.1.14 will fall back to ImageJ metadata (if any) if detecting series from OME-XML fails. The partial loading I cannot reproduce.

@cgohlke cgohlke closed this as completed Jan 15, 2021
@bryantChhun
Copy link
Author

Just a final note for any who encounter the same problem. After opening a micro-manager ome-tiff in FIJI and seeing that positions are encoded as independent series, it seems the access mode should not be imread but instead:

with TiffFile("path to ome-tiff") as tif:
    pos0 = tif.asarray(series=0)
    pos1 = tif.asarray(series=1)

@cgohlke
Copy link
Owner

cgohlke commented Jan 15, 2021

Since you are interested in series, it's probably better to query the series interface:

with TiffFile('image_stack_tpzc_50tp_2p_5z_3c_512k_1_MMStack_2-Pos000_000.ome.tif') as tif:
    for series in tif.series:
        series.dtype
        series.shape
        series.axes
        data = series.asarray()
dtype('uint16')
(50, 5, 3, 256, 256)
'TZCYX'
dtype('uint16')
(50, 5, 3, 256, 256)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants