ZEISS / pylibczirw

A simple and easy-to-use Python wrapper for libCZI - a cross-platform C++ library intended for providing read and write access to CZI documents.
https://zeiss.github.io/pylibczirw/
GNU Lesser General Public License v3.0
12 stars 3 forks source link

Request for Access to Individual Tiles in Mosaic Acquisitions - subblock access #36

Open CamachoDejay opened 2 months ago

CamachoDejay commented 2 months ago

Dear pylibCZIrw Team,

First, I'd like to express my appreciation for the work you've done on pylibCZIrw. The library has been incredibly useful for my image processing tasks, particularly with CZI files.

However, I would like to request a new feature that would significantly enhance the usability of pylibCZIrw for certain types of image analysis. Currently, pylibCZIrw abstracts away the concept of subblocks in both the reading and writing APIs. While this abstraction simplifies certain tasks, it also presents a limitation: there is no direct way to access individual images within a mosaic or tile acquisition.

Is your feature request related to a problem? Please describe.

Yes, the current implementation of pylibCZIrw abstracts away the concept of subblocks in both the reading and writing APIs. This abstraction limits access to individual images within a mosaic or tile acquisition, which is problematic when analyzing large images one tile at a time. This limitation hinders workflows in several scenarios, including:

Light-sheet microscopy data: These often involve large datasets where tile-specific corrections are essential for accurate analysis. Full slide/section imaging at high magnification: These images are typically large, and working with individual tiles is necessary for performing local image corrections and efficient data management. This limitation creates challenges when attempting to apply precise, tile-specific corrections or when converting large CZI files into formats like OME-Zarr.

Describe the solution you'd like

I would like pylibCZIrw to include functionality that allows users to access and manipulate individual tiles/subblocks within a mosaic acquisition. Specifically:

Reading API: The ability to retrieve and process individual tiles directly from a mosaic acquisition, allowing for more granular control over image analysis. Writing API: The ability to write or modify individual tiles within a CZI file, facilitating more efficient file creation and enabling advanced workflows like partial file updates. This feature would align pylibCZIrw more closely with user needs in complex imaging scenarios and reduce the reliance on alternative libraries for tile-specific processing.

Describe alternatives you've considered

The alternative solution currently in use is the aicspylibczi library, which does allow for accessing individual tiles. However, this requires switching between libraries, which complicates workflows and introduces additional dependencies. Ideally, having this capability integrated into pylibCZIrw would provide a more seamless experience.

Another workaround involves splitting large images into smaller regions manually, but this is not an efficient or scalable solution, particularly with very large datasets.

Additional context

The ability to access individual tiles would be particularly useful in translating large CZI files to formats like OME-Zarr, which is a key feature in our Data Management Plan, and other cloud compatible strategies. This functionality could also pave the way for implementing more advanced image processing techniques that require tile-level granularity, enhancing the overall utility of pylibCZIrw.

If needed, I can provide specific use cases or example datasets to illustrate the importance of this feature.

Thank you for considering this enhancement. Rafa

sebi06 commented 2 weeks ago

Hi @CamachoDejay

fully understood the need and this feature is already in our backlog, but not implemented yet. As a temporary workaround one can check this: https://github.com/sebi06/czitools/blob/main/src/czitools/read_tools/read_tools.py#L581

AFAIK the ome-zarr python tools only allow to write "tczyx" 5D arrays. See for example here:

https://github.com/sebi06/czitools/blob/main/src/czitools/write_tools/write_tools.py#L29

So can you provide some more information on this exact conversion process should look like? And what about using the NGFF Converter Tool?

zindy commented 2 hours ago

Dear @sebi06,

if I may hijack this thread, my use for reading and writing tiles would be to apply mosaic-picasso on a tiled image to generate a spectral unmixed (tiled?) image automatically. So I would definitely have a use for both reading and writing tiles.

I have this idea that I may be able to mimic how in QuPath and for colour deconvolution, the user first chooses a representative region of the image, on which the stain vectors are calculated.

In mosaic-picasso I may be able to split the "P" calculation from the representative crop, and apply it on individual tiles / channel group.

However, instead of realigning channels using skimage.registration.phase_cross_correlation() in mosaic_picasso.utils, maybe DaskFusion could be applied to the raw tile images first. Then, mosaic-picasso could be directly applied to the "chunks" computed by DaskFusion which would be aligned across channels (see the chunks visualisation in the notebook ).

For now, I will follow your suggestion in this image.sc forum thread:

Having that said, GitHub - AllenCellModeling/aicspylibczi: Python module utilizing libCZI for reading Zeiss CZI files. allow you to read individual images using the M-Index

But since you were asking for feedback and wishes, I think I also have a use case for reading and writing tiles using the pylibczirw library :-)

Kind regards, Egor