Skip to main content

py-clesperanto

Image.sc forum website PyPI Anaconda-Server Badge Contributors PyPI - Downloads GitHub stars GitHub forks License Python Version tests codecov Development Status DOI

[!NOTE] When starting a new project, consider using pyclesperanto instead of pyclesperanto_prototype.

py-clesperanto is a prototype for clesperanto - a multi-platform multi-language framework for GPU-accelerated image processing. We mostly use it in the life sciences for analysing 3- and 4-dimensional microsopy data, e.g. as we face it developmental biology when segmenting cells and studying their individual properties as well as properties of compounds of cells forming tissues.

Image data source: Daniela Vorkel, Myers lab, MPI-CBG, rendered using napari

clesperanto uses OpenCL kernels from CLIJ.

For users convenience, there are code generators available for napari and Fiji. Also check out the napari workflow optimizer for semi-automatic parameter tuning of clesperanto-functions.

Reference

The preliminary API reference is available here. Furthermore, parts of the reference are also available within the CLIJ2 documentation.

Installation

  • Get a conda/python environment, e.g. via mamba-forge.
  • If you never used python/conda environments before, please follow these instructions first.
conda create --name cle_39 python=3.9
conda activate cle_39
mamba install -c conda-forge pyclesperanto-prototype

OR using pip:

pip install pyclesperanto-prototype

Troubleshooting: Graphics cards drivers

In case error messages contain "ImportError: DLL load failed while importing cl: The specified procedure could not be found" see also or "clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR", please install recent drivers for your graphics card and/or OpenCL device. Select the right driver source depending on your hardware from this list:

Sometimes, mac-users need to install this:

mamba install -c conda-forge ocl_icd_wrapper_apple

Sometimes, linux users need to install this:

mamba install -c conda-forge ocl-icd-system

Linux user may have to install packages such as intel-opencl-icd or rocm-opencl-runtime depending on their GPU.

Computing on Central Processing units (CPUs)

If no OpenCL-compatible GPU is available, pyclesperanto-prototype can make use of CPUs instead. Just install oclgrind or pocl, e.g. using mamba / conda. Oclgrind is recommended for Windows systems, PoCL for Linux. MacOS typically comes with OpenCL support for CPUs.

mamba install  oclgrind -c conda-forge

OR

mamba install  pocl -c conda-forge

Owners of compatible Intel Xeon CPUs can also install a driver to use them for computing:

Example code

A basic image processing workflow loads blobs.gif and counts the number of objects:

import pyclesperanto_prototype as cle

from skimage.io import imread, imsave

# initialize / select GPU with "TX" in their name
device = cle.select_device("TX")
print("Used GPU: ", device)

# load data
image = imread('https://imagej.nih.gov/ij/images/blobs.gif')

# process the image
inverted = cle.subtract_image_from_scalar(image, scalar=255)
blurred = cle.gaussian_blur(inverted, sigma_x=1, sigma_y=1)
binary = cle.threshold_otsu(blurred)
labeled = cle.connected_components_labeling_box(binary)

# The maximium intensity in a label image corresponds to the number of objects
num_labels = labeled.max()
print(f"Number of objects in the image: {num_labels}")

# save image to disc
imsave("result.tif", labeled)

Example gallery

Select GPU

Image processing in Jupyter Notebooks

Counting blobs

Voronoi-Otsu labeling

3D Image segmentation

Cell segmentation based on membranes

Counting nuclei according to expression in multiple channels

Differentiating nuclei according to signal intensity

Detecting beads and measuring their size

Label statistics

Parametric maps

Measure intensity along lines

Crop and paste images

Inspecting 3D image data

Rotation, scaling, translation, affine transforms

Deskewing

Multiply vectors and matrices

Matrix multiplication

Mesh between centroids

Mesh between touching neighbors

Mesh with distances

Mesh nearest_neighbors

Export to igraph and networkx

Neighborhood definitions

Tissue neighborhood quantification

Neighbors of neighbors

Voronoi diagrams

Shape descriptors based on neighborhood graphs

Measuring distances between labels in two label images

Tribolium morphometry + Napari

Tribolium morphometry (archived version)

napari+dask timelapse processing

Technical insights

Browsing operations

Interactive widgets

Automatic workflow optimization

Tracing memory consumtion on NVidia GPUs

Exploring and switching between GPUs

Interoperability with cupy

Using the cupy backend

Big data handling with Dask GPU clusters

Related projects

napari-pyclesperanto-assistant: A graphical user interface for general purpose GPU-accelerated image processing and analysis in napari.

napari-accelerated-pixel-and-object-classification: GPU-accelerated Random Forest Classifiers for pixel and labeled object classification

napari-clusters-plotter: Clustering of objects according to their quantitative properties

Benchmarking

We implemented some basic benchmarking notebooks allowing to see performance differences between pyclesperanto and some other image processing libraries, typically using the CPU. Such benchmarking results vary heavily depending on image size, kernel size, used operations, parameters and used hardware. Feel free to use those notebooks, adapt them to your use-case scenario and benchmark on your target hardware. If you have different scenarios or use-cases, you are very welcome to submit your notebook as pull-request!

See also

There are other libraries for code acceleration and GPU-acceleration for image processing.

Feedback welcome!

clesperanto is developed in the open because we believe in the open source community. See our community guidelines. Feel free to drop feedback as github issue or via image.sc

Download files

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

Source Distribution

pyclesperanto_prototype-0.24.6.tar.gz (209.9 kB view details)

Uploaded Source

Built Distribution

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

pyclesperanto_prototype-0.24.6-py3-none-any.whl (624.2 kB view details)

Uploaded Python 3

File details

Details for the file pyclesperanto_prototype-0.24.6.tar.gz.

File metadata

  • Download URL: pyclesperanto_prototype-0.24.6.tar.gz
  • Upload date:
  • Size: 209.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for pyclesperanto_prototype-0.24.6.tar.gz
Algorithm Hash digest
SHA256 07e292867df39cd809e46e6ca033494e437c0f6f012a56540a765f649c056ead
MD5 19bbf0b968610253f3d2ee170d8a2847
BLAKE2b-256 4c3e3e13675e00bf6018b9b6531607f0a8023f8ee2157465c83364baf59064b0

See more details on using hashes here.

File details

Details for the file pyclesperanto_prototype-0.24.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pyclesperanto_prototype-0.24.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c023b634857268ea947d7f8417ab7e4582c1e44b6e71dfe787bff09bd772da09
MD5 260af48181da87697e6d3d4cc951bb4b
BLAKE2b-256 3a50c363124e88277db82aa21ec1cc39d9f5d464cd2f980fcebfbcca74a1b8d6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.24.6 This release

2 files

0.24.5

2 files

0.24.4

2 files

0.24.3

2 files

0.24.2

2 files

0.24.1

2 files

0.24.0

2 files

0.23.6

2 files

0.23.5

2 files

0.23.4

2 files

0.23.3

2 files

0.23.2

2 files

0.23.1

2 files

0.23.0

2 files

0.22.1

2 files

0.22.0

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.20.0

2 files

0.19.4

2 files

0.19.3

2 files

0.19.2

2 files

0.19.1

2 files

0.19.0

2 files

0.18.4

2 files

0.18.3

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.5

2 files

0.15.4

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.12.0

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.10

2 files

0.10.9

2 files

0.10.8

2 files

0.10.7

2 files

0.10.5

2 files

0.10.4

2 files

0.10.0

2 files

0.9.9

2 files

0.9.7

2 files

0.9.5

2 files

0.9.4

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.0.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page