fractal-napari-plugins-collection / napari-feature-classifier

BSD 3-Clause "New" or "Revised" License
21 stars 5 forks source link

napari-feature-classifier

License PyPI Python Version tests codecov napari hub

An interactive classifier plugin that allows the user to assign objects in a label image to multiple classes and train a classifier to learn those classes based on a feature dataframe.

Usage

To use the napari-feature-classifier, you need to have a label image and corresponding measurements: as a csv file, loaded to layer.features or in an OME-Zarr Anndata table loaded with another plugin. Your feature measurements need to contain a label column that matches the label objects in the label image. These interactive classification workflows are well suited to visually define cell types, find mitotic cells in images, do quality control by automatically detecting missegmented cells and other tasks where a user can easily assign objects to groups.

Prepare the label layer:

Initialize a classifier:

Classify objects:

Classifier_annotation

Apply the classifier to additional images:

Export classifier results

Batch mode result export

(To be updated: Create a new notebook to run batch processing, this is for the older version of the classifier) There is a simple workflow for the classifier in the examples folder:

Initializing the Annotator

You can use the annotation functionality also independently from the classifier Start the annotator widget by going to Plugins -> napari-feature-classifier -> Annotator Select names for your classes. You can name up to 9 classes. Only classes that you give a name will be created upon initialization. Then click Initialize.

Screenshot 2023-02-16 at 14 49 38

A annotator widget opens. Use the Radio-Buttons to select what class you're annotating (or keybindings for 1-9 for classes, 0 for deselect). The annotator will always work on the currently selected label layer. While the annotator is open, you can't edit the labels. Restart napari to allow editing of labels again.

Screenshot 2023-02-16 at 14 50 00

The annotations are saved in the layer.features table of the corresponding label layer as an annotations column.

Screenshot 2023-02-16 at 15 01 01

Installation

This plugin is written for the new napari npe2 plugin engine. Thus, it requires napari >= 0.4.13. Activate your environment where you have napari installed (or install napari using pip install "napari[all]"), then install the classifier plugin:

pip install napari-feature-classifier

The layer.features dataframes have some issues in napari 0.4.17 (see here). They seem to be working again in the nighlty builds. To set up a nightly builds napari env, do the following:

conda create -n classifier-dev-napari-main -c "napari/label/nightly" -c conda-forge napari python=3.10 -y

Similar napari plugins

If you're looking for other classification approaches, apoc by Robert Haase has a pixel classifier in napari and an object classification workflow:
napari-accelerated-pixel-and-object-classification (APOC)
Alternatively, Clément Cazorla has built napari-svetlana, a deep learning based classifier

Release process

  1. Update the version number in src/napari-feature-classifier/init.py
  2. Update the version in setup.cfg
  3. Add a Github release with a new version tag (matching the version set above)
  4. Once tests pass, this should automatically be deployed to pypi
  5. Wait for conda automation to make a PR for an updated conda release (see https://github.com/conda-forge/napari-feature-classifier-feedstock). This can take 1-2 days. Make sure that PR gets merged.

Contributing

Contributions are very welcome.

License

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

Issues

If you encounter any problems, please [file an issue] along with a detailed description.

Contributors

Joel Lüthi & Max Hess