Skip to main content

A python module and a python extension for Zeiss (CZI/ZISRAW) microscopy files.

Project description

pylibczi

C++ Build & Test Python Build & Test codecov License: GPL v3

Python module to expose libCZI functionality for reading (subset of) Zeiss CZI files and meta-data.

Usage

The first example show how to work with a standard CZI file (Single or Multe-Scene). The second example shows how to work with a Mosaic CZI file.

Example 1: Read in a czi and select a portion of the image to display

import numpy as np
import pylibczi
import pathlib
from PIL import Image

pth = pathlib.Path('/allen/aics/assay-dev/MicroscopyData/Sue/2019/20190610/20190610_S02-02.czi')
czi = pylibczi.CziFile(pth)

# Get the shape of the data, the coordinate pairs are (start index, size)
dimensions = czi.dims()  # {'Z': (0, 70), 'C': (0, 2), 'T': (0, 146), 'S': (0, 12), 'B': (0, 1)}

# Load the image slice I want from the file
img, shp = czi.read_image(S=4, T=11, C=0, Z=30) 

# shp = [('S', 1), ('T', 1), ('C', 1), ('Z', 1), ('Y', 1300), ('X', 1900)]  # List[(Dimension, size), ...]
# img.shape = (1, 1, 1, 1, 1300, 1900)   # numpy.ndarray

# Normalize the image 
norm_by = np.percentile(img[0, 0, 0,], [50, 99.8])

# Scale the numpy array values and cast them back to integers in the 0 to 255 range
i2 = np.clip((img - norm_by[0])/(norm_by[1]-norm_by[0]), 0, 1)*255

img_disp = Image.fromarray(i2[0,0,0,0,200:1100,500:1000].astype(np.uint8))

Colony Image

Example 2: Read in a mosaic file

import numpy as np
import pylibczi
import pathlib
from PIL import Image

mosaic_file = pathlib.Path('~/Data/20190618_CL001_HB01_Rescan_002.czi').expanduser()
czi = pylibczi.CziFile(mosaic_file)

# Get the shape of the data
dimensions = czi.dims()   # {'C': (0, 5), 'S': (0, 16), 'B': (0, 1)}

czi.is_mosaic()  # True 
 # Mosaic files ignore the S dimension and use an internal mIndex to reconstruct, the scale factor allows one to generate a manageable image
mosaic_data = czi.read_mosaic(C=1, scale_factor=0.1) 

mosaic_data.shape  # (1, 1, 6265, 6998)

norm_by = np.percentile(mosaic_data, [5, 98])
normed_mosaic_data = np.clip((itwo - norm_by[0])/(norm_by[1]-norm_by[0]), 0, 1)*255
img = Image.fromarray(normed_mosaic_data[0,0, 250:750, 250:750].astype(np.uint8))

Mosaic Histology Image

Installation

The preferred installation method is with pip install. This will install the pylibczi python module and extension binaries (hosted on PyPI):

pip install pylibczi

Documentation

Documentation is available on readthedocs.

Build

Use these steps to build and install pylibczi locally:

  • Clone the repository including submodules (--recurse-submodules).
  • Requirements:
    • libCZI requires a c++11 compatible compiler. Built & Tested with clang.
    • Development requirements are those required for libCZI: libpng, zlib
    • Install the package:
      pip install .
      pip install -e .[dev] # for development (-e means editable so changes take effect when made)
      pip install .[all] # for everything including jupyter notebook to work with the Example_Usage above
      
    • libCZI is automatically built as a submodule and linked statically into pylibczi.
  • Note: If you get the message EXEC : Fatal Python error : initfsencoding: unable to load the file system codec ... ModuleNotFoundError: No module named 'encodings' on windows you need to set PYTHONHOME to be the folder the python.exe you are compiling against lives in.

License

The GPLv3 license is a consequence of libCZI which imposes GPLv3. If you wish to use libCZI or this derivative in a commercial product you'll need to talk to Zeiss.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aicspylibczi-2.1.0-cp37-cp37m-win_amd64.whl (386.4 kB view details)

Uploaded CPython 3.7mWindows x86-64

aicspylibczi-2.1.0-cp37-cp37m-manylinux2010_x86_64.whl (547.6 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

aicspylibczi-2.1.0-cp37-cp37m-macosx_10_13_x86_64.whl (494.3 kB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

File details

Details for the file aicspylibczi-2.1.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: aicspylibczi-2.1.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 386.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

File hashes

Hashes for aicspylibczi-2.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ce69bb26b095457d78ef05d1a5309893585ce5eaf3f33a762fd3f12479076f50
MD5 0d39a2707951d9f6419a8e75affeb61f
BLAKE2b-256 16dc87bb62038958312ddcb6267434954c7b85788271bd1392c67dc6accaffbe

See more details on using hashes here.

File details

Details for the file aicspylibczi-2.1.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: aicspylibczi-2.1.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 547.6 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

File hashes

Hashes for aicspylibczi-2.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2b93e4aed80f9d0a0092b4b5b602a99f5680eb041c7d03eb13a8dd404d7d986d
MD5 8767493842c3afeac61fc3e1b5a551fb
BLAKE2b-256 f3cda1031af76d55dbae45ed4ba7fc4296e94faeaa40d4461654ff484de60337

See more details on using hashes here.

File details

Details for the file aicspylibczi-2.1.0-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: aicspylibczi-2.1.0-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 494.3 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

File hashes

Hashes for aicspylibczi-2.1.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3b5228fd471751b94c6ac712a37504b30bec6bda302d66d665afeb2b5bae0945
MD5 3e8b766e3d2d04cc6aaed8bdb76fa1ff
BLAKE2b-256 2e3cdbc3f2f3deaeaad60fbebfd82ef19c3229cbd9c1fa4363e00ea04646b109

See more details on using hashes here.

Supported by

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