Skip to main content

Tools to simplify reading CZI (Carl Zeiss Image) meta and pixel data

Project description

czitools

PyPI PyPI - Downloads License Python Version Development Status

This repository provides a collection of tools to simplify reading CZI (Carl Zeiss Image) pixel and metadata in Python. In addition it also contains other useful utilities to visualize CZI images inside Napari (needs to be installed). It is also available as a Python Package on PyPi

Reading the metadata

Please check use_metadata_tools.py for some examples.

# get the metadata at once as one big class
mdata = czimd.CziMetadata(filepath)

# get only specific metadata
czi_dimensions = czimd.CziDimensions(filepath)
print("SizeS: ", czi_dimensions.SizeS)
print("SizeT: ", czi_dimensions.SizeT)
print("SizeZ: ", czi_dimensions.SizeZ)
print("SizeC: ", czi_dimensions.SizeC)
print("SizeY: ", czi_dimensions.SizeY)
print("SizeX: ", czi_dimensions.SizeX)

# try to write XML to file
xmlfile = czimd.writexml(filepath)

# get info about the channels
czi_channels = czimd.CziChannelInfo(filepath)

# get the complete metadata from the CZI as one big object
czimd_complete = czimd.get_metadata_as_object(filepath)

# get an object containing only the dimension information
czi_dimensions = czimd.CziDimensions(filepath)

# get an object containing only the dimension information
czi_scale = czimd.CziScaling(filepath)

# get an object containing information about the sample
czi_sample = czimd.CziSampleInfo(filepath)

# get info about the objective, the microscope and the detectors
czi_objectives = czimd.CziObjectives(filepath)
czi_detectors = czimd.CziDetector(filepath)
czi_microscope = czimd.CziMicroscope(filepath)

# get info about the sample carrier
czi_sample = czimd.CziSampleInfo(filepath)

# get additional metainformation
czi_addmd = czimd.CziAddMetaData(filepath)

# get the complete data about the bounding boxes
czi_bbox = czimd.CziBoundingBox(filepath)

Reading CZI pixel data

While the pylibCZIrw is focussing on reading individual planes it is also helpful to read CZI pixel data as a STZCYX(A) stack. Please check use_read_tools.py for some examples.

# return a dask or numpy array with dimension order STZCYX(A)
array6d, mdata, dim_string6d = read_tools.read_6darray(filepath,
                                                       output_order="STCZYX",
                                                       use_dask=True,
                                                       chunk_zyx=False,
                                                       # T=0,
                                                       # Z=0
                                                       # S=0
                                                       # C=0
                                                       )

if array6d is None:
    print("Empty array6d. Nothing to display in Napari")
else:

    # show array inside napari viewer
    viewer = napari.Viewer()
    layers = napari_tools.show(viewer, array6d, mdata,
                               dim_string=dim_string6d,
                               blending="additive",
                               contrast='from_czi',
                               gamma=0.85,
                               show_metadata="tree",
                               name_sliders=True)

    napari.run()

5D CZI inside Napari

Colab Notebooks

Read CZI metadata

The basic usage can be inferred from this sample notebook:  Open In Colab

Read CZI pixeldata

The basic usage can be inferred from this sample notebook:  Open In Colab

Write OME-ZARR from 5D CZI image data

The basic usage can be inferred from this sample notebook:  Open In Colab

Write CZI using ZSTD compression

The basic usage can be inferred from this sample notebook:  Open In Colab

Show planetable of a CZI image as surface

The basic usage can be inferred from this sample notebook:  Open In Colab

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

The basic usage can be inferred from this sample notebook:  Open In Colab

Remarks

The code to read multi-dimensional with delayed reading using Dask array was heavily inspired by input from: Pradeep Rajasekhar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

czitools-0.5.0.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

czitools-0.5.0-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file czitools-0.5.0.tar.gz.

File metadata

  • Download URL: czitools-0.5.0.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for czitools-0.5.0.tar.gz
Algorithm Hash digest
SHA256 19b626507266e878a6980b02fb994d5e5f4e53ad2eda3caa0174757b70ca15d2
MD5 3715d1cc9755db66b50ab5d671615509
BLAKE2b-256 543e59d4ccca7ef0308b169d5bafee958c27a10e1d599db246ec98d3aaa46240

See more details on using hashes here.

File details

Details for the file czitools-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: czitools-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for czitools-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 521e618ae8e1760230e27dfd9ae16fcf2f09f4400edf14567bd20048671aa146
MD5 4ccc81ce0e202f34dc0e228ec4cab51c
BLAKE2b-256 4f20d582832977440991640f1f120729567b79643d8df41553ee4ec4af47d25b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page