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/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. Since version 0.11.1 py-clesperanto comes with a yet experimental cupy-based CUDA backend.
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 full reference is available as part of the CLIJ2 documentation.
Installation
- Get a conda/python environment, e.g. via mini-conda. If you never used python/conda environments before, please follow the instructions here first.
conda create --name cle_39 python=3.9
conda activate cle_39
- Install pyclesperanto-prototype using conda:
conda install -c conda-forge pyclesperanto-prototype
OR using pip:
pip install pyclesperanto-prototype
Mac-users please also install this:
conda install -c conda-forge ocl_icd_wrapper_apple
Linux users please also install this:
conda install -c conda-forge ocl-icd-system
Example code
A basic image procressing workflow loads blobs.gif and counts the number of gold particles:
import pyclesperanto_prototype as cle
from skimage.io import imread, imsave
# initialize GPU
device = cle.select_device("GTX")
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 maxmium intensity in a label image corresponds to the number of objects
num_labels = cle.maximum_of_all_pixels(labeled)
# print out result
print("Num objects in the image: " + str(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
Hashes for pyclesperanto_prototype-0.18.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2f75d0dd2c4fb8b30336ca8c94b1a4eb65d86a8b1f4db9d01055d132b500816 |
|
MD5 | dd456ad68547d4727a47209120721e30 |
|
BLAKE2b-256 | 040c31ddbf3030f790d4aa10712b5f38af347cbefd6d8cd1eaa08da8cd2fc173 |
Hashes for pyclesperanto_prototype-0.18.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 754e3cc93ce22bcee403e9477473fb4f141bcf7768d450471117f0e93ee028f6 |
|
MD5 | ebaac72b4fef866aca177a97b10ec5f8 |
|
BLAKE2b-256 | 9b83c4880c79609175a1493fd5e4a569baf4ff84a288aa4f7743c2ce43ce8113 |