clesperanto meets scikit-learn to classify pixels and objects in images, on a GPU using OpenCL. This repository contains the backend for python developers. User-friendly plugins for Fiji and napari can be found here:
- napari-accelerated-pixel-and-object-classification
- clijx-accelerated-pixel-and-object-classification
For training classifiers from pairs of image and label-mask folders, please see this notebook.
With a given blobs image and a corresponding annotation...
from skimage.io import imread, imshow
import pyclesperanto_prototype as cle
import numpy as np
import apoc
image = imread('blobs.tif')
imshow(image)
manual_annotations = imread('annotations.tif')
imshow(manual_annotations, vmin=0, vmax=3)
... objects can be segmented (see full example):
# define features: original image, a blurred version and an edge image
features = apoc.PredefinedFeatureSet.medium_quick.value
# Training
clf = apoc.ObjectSegmenter(opencl_filename='object_segmenter.cl', positive_class_identifier=2)
clf.train(features, manual_annotations, image)
# Prediction
segmentation_result = clf.predict(image=image)
cle.imshow(segmentation_result, labels=True)
With a given annotation, blobs can also be classified according to their shape (see full example).
features = 'area,mean_max_distance_to_centroid_ratio,standard_deviation_intensity'
# Create an object classifier
classifier = apoc.ObjectClassifier("object_classifier.cl")
# Training
classifier.train(features, segmentation_result, annotation, image)
# Prediction / determine object classification
classification_result = classifier.predict(segmentation_result, image)
imshow(classification_result)
- Object segmentation
- Object classification
- Object classification based on custom measurement tables
- Pixel classifier (including benchmarking).
- Output probability maps
- Continue training of pixel classifiers using multiple training image pairs
- Generating custom feature stacks
You can install apoc
using pip. Note: you need to install pyopencl in advance using conda:
conda install pyopencl
pip install apoc
Contributions are very welcome. Tests can be run with pytest
, please ensure
the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the BSD-3 license, "apoc" is free and open source software
If you encounter any problems, please open a thread on image.sc along with a detailed description and tag @haesleinhuepf.