Skip to content

Material to showcase and test several tools and packages releated to ZEN, OAD, ZEN-API. CZI image files and python packages related to those topics

License

Notifications You must be signed in to change notification settings

sebi06/ZEN_Python_CZI_Smart_Microscopy_Workshop

 
 

Repository files navigation

Smart Microscopy On-site Workshop: From Zero to Hero with ZEN and Open-Source Tools

Disclaimer

This content of this repository is free to use for everybody and purely experimental. The authors undertakes no warranty concerning the use of those scripts, image analysis settings and ZEN experiments, especially not for the examples using 3rd python modules. Use them on 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 python base environment (miniconda etc.)

conda activate base
conda install jupyterlab jupyter_server nb_conda_kernels

To run the notebooks locally it is recommended to create a fresh conda environment. Please feel free to use the provided YML file (at your own risk) to create such an environment:

conda env create --file env_smartmic.yml

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.

To test and run an arivis Cloud module locally one needs Docker Desktop installed.

ZEN API

ZEN API - General Information

ZEN API - ZEN Blu 3.12 - Documentation

ZEN API Python Examples

All examples can be found at: ZEN API Examples - ZEN Blue 3.12

ShowCase: Pixel Stream and Online Processing

ZEN running an acquisition while the PixelStream is processed by a python client. For the code can be found at: zenapi_streaming.py

ZEN API - Online Processing

ShowCase: Guided Acquisition

ZEN running a simple "guided acquisition" where the overview image is analyzed using python. Subsequently all found objects are acquire automatically. For the code can be found at: zenapi_guidedacq.py

ZEN API Guided Acquisition

Deep Learning Topics

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

The general idea is to learn how to label a dataset on arivis Cloud.

Dataset Name: Smart_Microscopy_Workshop_2025_Nucleus_Semantic

Annotated Dataset

  • label some nuclei "precisely"
  • label background areas and edges
  • embrace the idea of partial labeling

Partial Annotations

  • start a training to get a trained model as a *.czann file

Remark: The the modelfile: cyto2022_nuc2.czann can be found inside the repository.

For more detailed information please visit: Docs - Partial Annotations

Use the model in your python code

Once the model 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.

Open In Colab

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

The 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, arivisPro software platforms and also in your own code.

For details and more information examples please go to: czmodel

Train a simple model for semantic segmentation

Open In Colab

Train a simple model for regression

Open In Colab

Use the model inside Napari (experimental)

This plugin is purely experimental. The authors undertakes no warranty concerning its use.

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

It can install it via pip:

pip install napari-czann-segment

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

Train on arivis Cloud and use model in Napari

Using the czitools package (experimental)

This python package is purely experimental. The authors undertakes no warranty concerning its use.

For details please visit: czitools

Read CZI metadata

Open In Colab

Read CZI pixeldata

Open In Colab

Write OME-ZARR from 5D CZI image data

Open In Colab

Write CZI using ZSTD compression

Open In Colab

Show planetable of a CZI image as surface

Open In Colab

Read a CZI and segment using Voroni-Otsu provided by PyClesperanto GPU processing

Open In Colab

CZICompress - Compress CZI image files from the commandline

Starting with ZEN 3.9 ZSTD (Z-Standard) will be the new default compression method in ZEN (it was already available longer), but obviously there are already many existing CZI image files "out there" and how to deal with existing ZEN installations that can read uncompressed CZIs but not compressed CZIs?

Therefore we created a command line tool:

  • compress or decompress a single CZI file
  • versatile
  • scriptable
  • run in headless/server environments
  • run in cron jobs
  • cross-platform (focus on linux-x64 and win-x64)
  • public Github repository: CZICompress

General usage

Start the executable from the command line, providing the required command line arguments.

Usage: czicompress [OPTIONS]

Options:
-h,--help         Print this help message and exit

-c,--command COMMAND
                    Specifies the mode of operation: 'compress' to convert to a
                    zstd-compressed CZI, 'decompress' to convert to a CZI
                    containing only uncompressed data.

-i,--input SOURCE_FILE
                    The source CZI-file to be processed.

-o,--output DESTINATION_FILE
                    The destination CZI-file to be written.

-s,--strategy STRATEGY
                    Choose which subblocks of the source file are compressed.
                    STRATEGY can be one of 'all', 'uncompressed',
                    'uncompressed_and_zstd'. The default is 'uncompressed'.

-t,--compression_options COMPRESSION_OPTIONS
                    Specify compression parameters. The default is
                    'zstd1:ExplicitLevel=0;PreProcess=HiLoByteUnpack'.


Copies the content of a CZI-file into another CZI-file changing the compression
of the image data.
With the 'compress' command, uncompressed image data is converted to
Zstd-compressed image data. This can reduce the file size substantially. With
the 'decompress' command, compressed image data is converted to uncompressed
data.
For the 'compress' command, a compression strategy can be specified with the
'--strategy' option. It controls which subblocks of the source file will be
compressed. The source document may already contain compressed data (possibly
with a lossy compression scheme). In this case it is undesirable to compress the
data with lossless zstd, as that will almost certainly increase the file size.
Therefore, the "uncompressed" strategy compresses only uncompressed subblocks.
The "uncompressed_and_zstd" strategy compresses the subblocks that are
uncompressed OR compressed with Zstd, and the "all" strategy compresses all
subblocks, regardless of their current compression status. Some compression
schemes that can occur in a CZI-file cannot be decompressed by this tool. Data
compressed with such a scheme will be copied verbatim to the destination file,
regardless of the command and strategy chosen.

Usage example for single files from commandline (cmd.exe)

SET PATH=$PATH;C:\Users\y1mrn\Downloads\czicompress
cd /D D:\TestData

czicompress --command compress -i LLS-31Timepoints-2Channels.czi -o compressed.czi

Usage example with multiple files (bash)

export PATH=$PATH:/c/Users/y1mrn/Downloads/czicompress
cd /d/TestData

find -type f -name '*.czi' -not -iname '*zstd*' -exec czicompress.sh '{}' \;

CZICompress in Action in Ubuntu

CZIShrink - Compress CZI image files from a cross-platform UI

  • Cross Platform GUI App
  • Developed, tested and released on Win-x64 and Linux-x64
  • Designed to work with large CZI collections
  • Multi-threaded processing
  • Strictly non-destructive
  • Developed still as a private repo on GitHub => release as OSS planned soon

CZIShrink

CZIShrink - Share

CZIShrink in Action

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

napari-czitools (experimental)

This plugin is purely experimental. The authors undertakes 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.

It can install it via pip:

pip install napari-czitools

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

CZI and OME-ZARR (experimental)

All OME-ZARR related scripts here are purely experimental. The authors undertakes no warranty concerning the use of those scripts.

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

Convert CZI to OME-ZARR using ome-zarr

See: write_omezarr_adv.py

Convert CZI to OME-ZARR using ngff-zarr

See: write_omezarr_adv.py

Convert CZI to OME-ZARR HCS Plate using ome-zarr

See: write_omezarr_adv.py

Convert CZI to OME-ZARR HCS Plate using ngff-zarr

See: write_omezarr_adv.py

Useful Links


Name/Description Link Name/Description Link
Napari - Python-based image viewer GitHub pip - Python Package Installer PyPI
PyPi - Python Package Index PyPI pylibCZIrw - Python Package to read & write CZI files PyPI
pylibCZIrw - GitHub Repository for CZI files (Python) GitHub czmodel - Package for Pytorch & ONNX models PyPI
cztile - Python Package for tiling arrays PyPI arivis Cloud - DL Training Platform arivis Cloud
napari-czann-segment - Napari Plugin for DL models GitHub napari-czitools - Plugin for CZI files GitHub
CZI - Carl Zeiss Image Format ZEISS PyTorch PyTorch
ONNX ONNX libCZI - GitHub Repository for CZI files (C++) GitHub
czitools - Tools for CZI files PyPI Colab Colab
Docker Desktop Docker Desktop CZICompress - Shrink CZI files GitHub
CZIChecker - Check Integrity of CZI files GitHub ome-zarr - Python Implementation of NGFF Specs GitHub
NGFF - Next-generation File Formats NGFF ngff-zarr - Python Implementation of NGFF Specs GitHub

About

Material to showcase and test several tools and packages releated to ZEN, OAD, ZEN-API. CZI image files and python packages related to those topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 95.3%
  • Python 4.7%