Object-classification, dimensionality reduction and clustering

Author

Marina Cuenca

Published

January 5, 2026

Object classification in Napari

Pixel classification, dimensionality reduction, and automatic clustering are common data-driven approaches used to analyze complex image data. Pixel classification assigns each pixel to a class based on its intensity or multi-channel feature values, enabling tasks such as segmentation or tissue labeling without explicit object detection. Dimensionality reduction methods (such as PCA, UMAP, or t-SNE) compress high-dimensional feature spaces into fewer dimensions while preserving key patterns or relationships, making large imaging datasets easier to visualize and interpret. Automatic clustering methods (e.g. k-means or similar algorithms) then group pixels or objects into clusters based on feature similarity, allowing unbiased identification of recurring patterns or phenotypes without predefined labels.

Learning Outcomes

By the end of this tutorial, participants will be able to:

  • Train an object classifier with Napari
  • Filter labels
  • Extract morphological and intensity based parameters
  • Plot parameters in 2D
  • Apply a dimensionality reduction method
  • Visualize the results
  • Cluster subgroups of objects using K-means

These steps form a complete workflow: raw image β†’ segmentation β†’ cleanup β†’ labeling β†’ measurement β†’ data viz

We’ll use Lund.tif as the example image https://zenodo.org/records/17986091

Requirements: - Everything you need is in the toml file in the Pixi/napari-devbio folder https://github.com/cuenca-mb/pixi-napari-devbio

–

0. Open the image and inspect the histogram

In the terminal, go to the directory Pixi/napari-devbio and run:

pixi run napari

1. Open the image and create manual anotations

Drag and drop the file or

File β†’ Open File

Load image and generate labels layer

Load image and generate labels layer

We will be able to see and explore the stack, and we can change to a 3D rendering with the option Toogle 2D/3D view in the lower left button pannel. We will create a labels layer to anotate some ground truth for our object classifier.

In the left pannel, select the brush tool and make some background anotations with the brush. Then change to label 2 and make some object annotations (cells).

Draw the labels

Draw the labels

2. Train the object classifier

Go to

Tools β†’ Segmentation / labeling β†’ Object segmentation (APOC)

Brightness/Contrast histogram

Brightness/Contrast histogram

Select the raw data for training and the labels layer for ground truth. Then click Train. Observe the results in 3D. For better visualization you can hide the labels layer.

Train

Train

Observe labels result

Observe labels result

From this first round of training, very likely the result is not perfect. This is because our ground truth anotation was done on a single z slice, so the classifier will perform well only around that depth. We can do several rounds of training.

Select again the labels image, and in the 2D mode go to a different z. Perform new anotations, preserving the label orders for background and object. Then just click Train again and observe the new results. Repeat as needed. Note that a classifier file will be produced and overwritten after each training. This can be used for batch segmentation of data from the same experiment/microscope.

Modify labels layer

Modify labels layer

Re-train

Re-train

3. Filter small objects and quantify parameters

Now there might be some small objects that we want to filter. Go to

Tools β†’ Segmentation post-processing β†’ Exclude small labels

Then select the layer Result of ObjectSegmentation and impose a minimum size of 20 (it will say maximum size in napari, but it is a mistake from the developers). Run it and observe the final labels (hide the old labels for better visualization.

Exclude small objects

Exclude small objects

Observe filtered labels

Observe filtered labels

Now that we have a nice set of labels in 3D, we will quantify intensity and morphology based parameters for further analysis.

Go to

Tools β†’ Measurement tables β†’ Regionprops

Select all parameters except moments and click run.

Regionprops

Regionprops

Table

Table

We can export this table or visualize some of the data using the cluster plotter.

4. Data visualization with clusters plotter

Go to

Plugins β†’ napari-clusters-plotter β†’ Plotter widget

In here you can select any measurement (column) from the region props table and make scatter plots.

Plotter widget

Plotter widget

Scatter plot

Scatter plot

A very useful tool is that we can draw in the plot closed curves and the objects falling inside will be automatically colorcoded and visualized in the 3D rendered image. I recommend hiding all the other layers except the raw image.

By pressing shift, we can draw further subgroups.

Label IDs

Label IDs

This manual selection generates a new column in the regionprops table with the identifier for us to export and further analyse in other software.

5. Dimensionality reduction

Go to

Plugins β†’ napari-clusters-plotter β†’ Dimensionality Reduction Widget

This is a very useful tool in which we can apply a variety of dimensionality reduction methods to our list of parameters. In this example I used UMAPS. We can select how many components we want and after hitting run they will be added to our regionprops table.

Dimensionality Reduction

Dimensionality Reduction

UMAP

UMAP

After doing this, we can come back to the Plotter Widget and plot this two components of the UMAP and generate more complex clustering of the data manually.

UMAP viz

UMAP viz

Manual Cluster ID

Manual Cluster ID

6. Unsupervised clustering

But what if we don’t want to be biased when clustering the data in subgroups? We can use unsupervised methods includded in this plugin. Go to

Plugins β†’ napari-clusters-plotter β†’ Clustering Widget

Select the K-MEANS method, impose 3 clusters and run. This will generate a new column with the cluster ID for each object.

Clustering methods

Clustering methods

K-MEANS

K-MEANS

Now going back to the Plotter Widget, we can select the UMAP axis AND the K-MEAN cluster IDs to automatically colorcode the objects belonging to different classes.

Automatic clustering

Automatic clustering