pyclesperanto is the python package of clEsperanto - a multi-language framework for GPU-accelerated image processing. clEsperanto uses OpenCL kernels from CLIJ. This package relies on the CLIc back-end for processing.
Get a conda/python environment, e.b. via mini-conda. If you never used python/conda environments before, please follow the instructions here first.
conda create --name my_env python=3.10
conda activate my_env
Install pyclesperanto package using conda: (WIP, use pip instead)
conda install -c conda-forge pyclesperanto
OR using pip:
pip install pyclesperanto
Note: This project is under heavy development. General API, functions, and parameters are subject to change.
import pyclesperanto as cle
from skimage.io import imread, imsave
# initialize GPU
device = cle.select_device()
print("Used GPU: ", device)
image = imread("https://imagej.nih.gov/ij/images/blobs.gif")
# push image to device memory
input_image = cle.push(image)
# process the image
inverted = cle.subtract_image_from_scalar(input_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))
# read image from device memory
output_image = cle.pull(labeled)
imsave("result.tif", output_image)
More usage and example can be found as notebooks in the user documentation folder
Contributions are very welcome. Before spending effort on coding and filing a pull-request, please get in touch, [file an issue], and let's discuss your potential contribution.
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.