GPU-accelerated image processing in python using OpenCL
Project description
py-clesperanto
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
- Install pyclesperanto-prototype using mamba / conda:
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
Counting nuclei according to expression in multiple channels | |
Technical insights
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!
- Affine transforms
- Background subtraction
- Gaussian blur
- Convolution
- Otsu's thresholding
- Connected component labeling
- Extend labels
- Statistics of labeled pixels / regionprops
- Histograms
- Matrix multiplication
- Pixel-wise comparison
- Intensity projections
- Axis transposition
- Nonzero
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyclesperanto_prototype-0.24.5.tar.gz
.
File metadata
- Download URL: pyclesperanto_prototype-0.24.5.tar.gz
- Upload date:
- Size: 208.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa38b346e9beaa716fafeb205c7999302aed1b20c07b9749f52d290c278359bc |
|
MD5 | 7d631bb5493d78e7f85bf1379d4b3f83 |
|
BLAKE2b-256 | 59aefa33875c73625e24d4a1eaada7287269a39c9e68496e18e4dc288ed43a80 |
File details
Details for the file pyclesperanto_prototype-0.24.5-py3-none-any.whl
.
File metadata
- Download URL: pyclesperanto_prototype-0.24.5-py3-none-any.whl
- Upload date:
- Size: 624.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b00515744db9c8460710c59b31e67b93de2b15be0de9023cf66cb7d59119c7 |
|
MD5 | 083a5cc594ce7c519f6adb8b457684f7 |
|
BLAKE2b-256 | 431ae24cfe9505e0585cbdafb8ca00248db306149d3334680d469a2ce96ee78e |