Skip to main content

Accelerated Pixel and Object Classifiers based on OpenCL

Project description

Accelerated Pixel and Object Classifiers (APOC)

License PyPI Python Version tests codecov Development Status DOI

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:

For training classifiers from pairs of image and label-mask folders, please see this notebook.

Object segmentation

With a given blobs image and a corresponding annotation...

import apoc
from skimage.io import imread, imshow
import pyclesperanto_prototype as cle

image = imread('blobs.tif')
imshow(image)

img.png

manual_annotations = imread('annotations.tif')
imshow(manual_annotations, vmin=0, vmax=3)

img.png

... 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)

img.png

Object classification

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)

cle.imshow(classification_result, labels=True)

img.png

Object selector

If the desired analysis goal is to select objects of a specific class, the object selector can be used (see full example).

features = 'area,mean_max_distance_to_centroid_ratio,standard_deviation_intensity'

cl_filename = "object_selector.cl"

# Create an object classifier
apoc.erase_classifier(cl_filename) # delete it if it was existing before
classifier = apoc.ObjectSelector(cl_filename, positive_class_identifier=1)

# train it
classifier.train(features, labels, annotation, image)

result = classifier.predict(labels, image)
cle.imshow(result, labels=True)

img.png

Object merger

APOC also comes with a ObjectMerger allowing to train a classifier on label edges for deciding to merge them or to keep them. (See full example)

feature_definition = "touch_portion mean_touch_intensity"

classifier_filename = "label_merger.cl"

apoc.erase_classifier(classifier_filename)
classifier = apoc.ObjectMerger(opencl_filename=classifier_filename)

classifier.train(features=feature_definition,
                 labels=oversegmented,
                 sparse_annotation=annotation,
                 image=background_subtracted) 

merged_labels = classifier.predict(labels=oversegmented, image=background_subtracted)
cle.imshow(merged_labels, labels=True)

img.png

More detailed examples

Installation

You can install apoc using conda or pip:

conda install -c conda-forge apoc-backend

OR:

conda install pyopencl
pip install apoc

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

Contributing

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.

License

Distributed under the terms of the BSD-3 license, "apoc" is free and open source software

Issues

If you encounter any problems, please open a thread on image.sc along with a detailed description and tag @haesleinhuepf.

Project details


Download files

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

Source Distribution

apoc-0.12.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

apoc-0.12.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file apoc-0.12.0.tar.gz.

File metadata

  • Download URL: apoc-0.12.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for apoc-0.12.0.tar.gz
Algorithm Hash digest
SHA256 c6e5264f2ac0420e5f8e2b23ad16927126d75280bb12f0341480ef9853973263
MD5 eac0016ff2997e80aab6a0dc7fb5d325
BLAKE2b-256 12bb169a16a810cac65b6c5f0f69cc4d1e4df17269194efb072721e6e899fbf1

See more details on using hashes here.

File details

Details for the file apoc-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: apoc-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for apoc-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0603edad68ab5fdd46e5e2ddada5749f4fb55e475e0a49ce0aab9b599dae2c2d
MD5 b1a82b9c9a99670f4c1191e8dfc349c5
BLAKE2b-256 df714aedecc8c3d92e6496248b5b01a45fb28705ea305284fd3875073f4344bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page