Skip to content

sebi06/ZEN_Python_Workshop

Repository files navigation

ZEN Python Workshop

Disclaimer: This content of this repository is free to use for everybody and purely experimental. The authors undertake no warranty concerning the use of the code examples, scripts and notebooks, especially not for the examples using 3rd-party Python modules.

Use them at your own risk!

By using any of those examples you agree to this disclaimer.

General Remarks

This repository contains scripts and notebooks showcasing several tools and scripts centered around ZEN, CZI image files, deep-learning models and related python packages.

Prerequisites

Install Pixi

  • Download and install Miniconda if needed: Download Pixi
  • Pixi Binaries can be found here: Pixi Binary Release
  • check if installation was successful and check for updates:
pixi --version
pixi self-update

Install Python Environment

pixi install

Clone the repository

To clone this repository:

  • navigate to a folder of your choice
  • open a terminal or command window
git clone https://github.com/sebi06/ZEN_Python_Workshop

Additional Remarks

Important: If one wants to test the labeling & training directly on arivis Cloud or create a module it is required to have an account.

To use Colab one needs to have a Google account.

C++ library: libCZI

libCZI is an Open Source Cross-Platform C++ library to read and write CZI.

libCZI

libCZI is a library intended for providing read and write access:

  • reading subblock pixeldata
  • works with tiled and pyramidal images
  • composing multi-channel images with tinting and applying a gradation curves
  • access metadata
  • writing subblocks and metadata
  • used by aicspylibczi and bioio-czi

pylibCZIrw (python wrapper for libCZI)

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.

pylibCZIrw

Simple and easy-to-use Python wrapper for libCZI providing read and write access to CZI image documents

  • reading any 2D plane and ROIs from any dimension
  • On-the-fly interpolations
  • access metadata
  • writing 2D planes to any dimension
  • Used by bioio-czi library

Example Notebooks using pylibCZIrw

Topic Link
Use pylibCZIrw Open In Colab
Segment with Voronoi-Otsu Open In Colab

czitools (experimental)

This repository provides a collection of tools to simplify reading CZI (Carl Zeiss Image) pixel and metadata in Python. It is available as a Python Package on PyPi.

Disclaimer: czitools is an experimental Python package and not officially supported by ZEISS. The authors undertake no warranty concerning its use.

PyPi: https://pypi.org/project/czitools/ Repo: https://github.com/sebi06/czitools Docs: https://sebi06.github.io/czitools/latest/ License: GPL v3

  • read complete stacks or substacks of CZI as numpy or dask arrays incl. lazy-loading
  • read complete or partial metadata in a structured format
  • get the plantable from a CZI
  • create OME-ZARR from CZI

Example Notebooks using czitools

Topic Link
Read CZI Metadata Open In Colab
Read CZI Pixel Data Open In Colab
Get CZI PlaneTable Open In Colab
OME-ZARR from CZI Open In Colab

napari-czitools (experimental)

Disclaimer: napari-czitools is an experimental Napari plugin and not officially supported by ZEISS. The authors undertake no warranty concerning its use.

In order to use such a model one needs a running python environment with Napari and the napari-czitools plugin installed.

For more detailed information about the plugin please go to: Napari Hub - napari-czitools

To start Napari including the plugin napari-czitools use:

pixi run start-napari

OME-ZARR Examples

CZI image files can be converted to OME-ZARR using various approaches.

Disclaimer: All tools and scripts related to CZI -> OME-ZARR conversion are not officially supported by ZEISS and are purely experimental. The authors undertake no warranty concerning its use.

CZI-2-OMEZARR Conversion Playground

Simple & experimental UI aiming to provide a playground to explore different option to convert CZI file to OME-ZARR files incl options for a HCS layout.

CZI-2-OMEZARR UI Converter

To start it use:

pixi run start-omeui

Example notebooks OME_ZARR

Topic Link
OME-ZARR from CZI Open In Colab
Analyze HCS OME_ZARR Open In Colab

Deep Learning Topics

Train a Deep-Learning Model for Semantic Segmentation on arivis Cloud

It is straightforward to train AI models for semantic and instance segmentation on arivis Cloud. The training is based on a zero-code approach and especially suited for beginners.

For the examples below the focus is on Semantic Segmentation only.

  • login to arivis Cloud (requires account)
  • create New Dataset
  • upload the test images inside: ..\notebooks\nucleus_data\images\
  • all images will be converted to CZIs automatically

Annotated Dataset

  • start labeling the data by pressing Annotate
  • create labels manually or use the AI-assisted tool (SAM-based)
  • label some nuclei "precisely"
  • label background areas and edges
  • embrace the idea of partial labeling

Partial Annotations

For more detailed information please visit: Docs - Partial Annotations

Once the training is finished one will get notified via mail and the model can be downloaded as an *.czann file, which is an ONNX model plus model metadata. For detail see: czmodel

Remark: The model file cyto2022_nuc2.czann can be found inside the repository and can be used directly for the examples.

Use the CZANN model in your python code

Once the model (*.czann) is trained it can be downloaded directly to your hard disk and used to segment images in ZEN or arivis Pro or your own python code.

Topic Link
Run CZANN Model from arivis Cloud Open In Colab

Train your own model and package (as *.czann) using the czmodel package

The czmodel package provides simple-to-use conversion tools to generate a CZANN file from a PyTorch or ONNX model that resides in memory or on disk to be usable in the ZEN, arivis Cloud, arivis Pro software platforms and in your own code.

For details and more information examples please go to: czmodel

Train a simple model for semantic segmentation

Topic Link
Train Model and export as CZANN Open In Colab

Use the model inside Napari (experimental)

Disclaimer: napari-czann-segment is an experimental Napari plugin and not officially supported by ZEISS. The authors undertakes no warranty concerning its use.

For more detailed information about the plugin please go to: Napari Hub - napari-czann-segment

Train on arivis Cloud and use model in Napari

To start Napari including the plugin napari-czann-segment use:

pixi run start-napari

CZICheck - Check CZI for internal errors

CZICheck is a command-line application developed using libCZI, enabling users to assess the integrity and structural correctness of a CZI document.

Checking the validity of a CZI becomes more complex the closer one is to the application domain (e.g. application-specific metadata). So this console application is more of a utility to help users who are directly using libCZI, or its python wrapper pylibCZIrw & pylibCZIrw_github, than it is an official validation tool for any ZEISS-produced CZIs.

CZICheck runs a collection of checkers which evaluate a well defined rule. Each checker reports back findings of type Fatal, Warn, or Info.

Please check the tool's internal help by running CZICheck.exe --help and check additional documentation on the repository.

CZIChecker in Action

Useful Links


Name/Description Link Name/Description Link
Napari - Python-based image viewer Napari pip - Python Package Installer PiP
PyPi - Python Package Index PyPI OME-ZARR Python Library OME-ZARR
pylibCZIrw - Reading & Writing CZI files (Python) pylibCZIrw czmodel - Package for Pytorch & ONNX models czmodel
cztile - Python Package for tiling arrays cztile arivis Cloud - DL Training Platform arivis Cloud
napari-czann-segment - Napari Plugin for DL models napari-czann-segment napari-czitools - Plugin for CZI files napari-czitools
CZI - Carl Zeiss Image Format CZI Image Format PyTorch - tensor library for deep learning using GPUs and CPUs. PyTorch
ONNX - Open Neural Network Exchange ONNX libCZI - Reading & Writing CZI files (C++) libCZI
czitools - Tools for CZI files czitools Colab - Cloud-based interactive Jupyter Notebooks Colab
Docker Desktop Docker Desktop CZICompress - Shrink CZI files CZICompress
CZIChecker - Check Integrity of CZI files CZICheck ome-zarr - Python Implementation of NGFF Specs OME-ZARR
NGFF - Next-generation File Formats NGFF-ZARR ngff-zarr - Python Implementation of NGFF Specs NGFF-ZARR
ome-zarr-models - minimal package for reading OME-Zarr OME-ZARR_MODELS ngio - intuitive interface for OME-Zarr files NGIO
NGFF Converter - converter for bioimaging data NGFF-Converter bioio-conversion - BioIO conversion tool for going between image formats bioio-conversion
Czifile is a pure Python library for reading CZI czifile

About

Code, Examples and Explanations around ZEN, the CZI Image Format and related Python libraries.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors