Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Adding interactive classification and going 3D

In this final module we add a small interactive classification step to our pipeline, this time working on the Points layer. Finally, we test out our full workflow on 3D data!

1. Classify objects based on their features

Let’s finish up this workflow by adding a classification step. We calculate some more object properties, and we add a new magic function that updates the Points visualisation based on the features and our thresholds, and which saves which objects should be marked as good.

You should recognize the magicgui pattern (with a new trick, RangedSliders!) and the code for extracting object properties via regionprops_table. What’s new is how we set border and face colors on the Points layer based on properties and a colormap, as well as their size based on the size of the underlying object. We also update the symbol when a point satisfies our thresholds!

07_classify_features.py

Loading...

2. Going 3D

Everything we’ve built so far works on a 2D slice of cells3d. But napari is n-dimensional — let’s load the full 3D volume and see our pipeline in action across all slices.

The best part? No code changes needed, other than loading the data. napari’s widgets automatically operate on whatever data the selected layer contains, whether it’s 2D or 3D.

08_going_3D.py

Using the slider at the bottom of the viewer to scroll through the third dimension, you can observe the effects of the pipeline on individual 2D slices. However, you can also switch to 3D using the 2D/3D button at the bottom left of the viewer.

Each view has its advantages and disadvantages: for example, in 3D you can more easily see object connectivity and general segmentation effectiveness, while in 2D you can see internal holes that would be otherwise invisible, as well as add point annotations as seed for the watershed step.

Try using both modes to do a final segmentation and classification of this data. Just watch out: the processing speed will be much slower than before!

Loading...

Recap

Next steps: Turning this into a plugin

Now that you have a complete interactive segmentation workflow, you can package it as a reusable napari plugin using the napari plugin template.

copier copy https://github.com/napari/napari-plugin-template.git my-plugin

See the napari plugin documentation for more details. The napari hub (napari-hub.org) is where you can share your plugin with the community!