Cluster Measurements (UMAP/HDBSCAN) - User Manual
Dragonfly Prototype Apps · Cluster Measurements (UMAP/HDBSCAN)...
Version 1.0 · 2026-07-09
English Manual
Contents
1. Overview
2. Use Cases
3. Installation and Enabling
4. Runtime Environment and First-Run Setup
5. Interface Guide
6. Usage Steps
7. Parameter Reference
8. Outputs
9. FAQ and Troubleshooting
10. Notes and Known Limitations
11. References
1. Overview
Cluster Measurements (UMAP/HDBSCAN) is a Dragonfly plugin that performs unsupervised clustering of a MultiROI's per-label measurement table. Once you have computed per-label measurements (volume, surface area, sphericity, shape factor, orientation, ...) on the hundreds or thousands of labels in a MultiROI, those measurements live on the MultiROI as scalar slots. This plugin reads the slots you tick, treats each label as a feature vector, automatically sorts the labels into a handful of morphologically or compositionally similar clusters, writes the result back as a NEW MultiROI scalar slot, and saves a 2D scatter PNG.
The pipeline is: read the ticked scalar slots into a feature matrix (one row per label) -> optionally standardize (StandardScaler) -> embed to 2D with UMAP / t-SNE / PCA -> cluster with KMeans (fixed number of clusters) or HDBSCAN (minimum cluster size) -> write each label's cluster id back as a new scalar slot -> save a 2D scatter colored by cluster. Afterwards, simply color the MultiROI by that new slot in Dragonfly to see the groups.
Underlying engines and algorithms (all permissively licensed): dimensionality reduction and clustering use scikit-learn (PCA, t-SNE, KMeans, StandardScaler), umap-learn (UMAP reduction) and hdbscan (HDBSCAN density clustering); numerics rely on numpy; the 2D scatter is drawn with matplotlib (Agg head-less backend).
Licensing: the plugin code follows the DragonflyPrototypeLabs repository's terms; every compute engine is permissive -- scikit-learn (BSD-3-Clause), umap-learn (BSD-3-Clause), hdbscan (BSD-3-Clause), matplotlib (PSF/BSD-style), numpy (BSD).
2. Use Cases
The plugin is aimed at grouping particles, pores, grains, or cells in materials and life science: using per-label measurements (volume, surface area, shape factor, sphericity, orientation, ...) it automatically sorts thousands of labels into a few similar groups for classification, outlier detection and structural characterization.
- Particle / pore grouping: sort CT-segmented pores or particles by volume, sphericity, and shape factor into large/small or spherical/plate-like groups for quantitative classification.
- Grain characterization: group grains by their morphological measurements to spot anomalous grains or distinct grain families.
- Cell grouping: in life-science imagery, group cells into morphological categories from volume, shape, etc.
- Outlier detection: with HDBSCAN, labels that belong to no dense group are flagged as noise (id -1), making it easy to pick out anomalous structures.
- Dimensionality-reduction visualization: even without strict grouping, the 2D scatter lets you see how the high-dimensional measurements distribute in 2D.
3. Installation and Enabling
1. Download the Prototype Apps online package from ImageFly and extract it. Close Dragonfly, run install_prototype_apps.exe and select the Dragonfly version to install into.
2. Start Dragonfly, open Prototype Apps ▸ App Store and search for Cluster Measurements (UMAP/HDBSCAN). If an Enable button is shown, click it and follow the sign-in, download or installation prompts.
3. Restart Dragonfly when prompted, then open Cluster Measurements (UMAP/HDBSCAN) from the Prototype Apps menu. Return to App Store to enable or disable it later.
4. Runtime Environment and First-Run Setup
The heavy compute (scikit-learn / umap-learn / hdbscan / matplotlib) runs in a dedicated virtual environment (venv), never touching Dragonfly's own Python. Before first use you must click Setup Environment once in the panel.
On Dragonfly 2027.1 (Python 3.14) the bundled Python cannot build this environment: install a python.org Python (3.12, 3.13 or 3.14) and enter it in the panel's Base Python field; Dragonfly 2025.1 needs no separate Python.
What Setup Environment does
Setup Environment creates a dedicated venv and installs scikit-learn, umap-learn, hdbscan and matplotlib. On Dragonfly 2027.1, set Base Python to a python.org Python 3.12, 3.13 or 3.14 executable. On 2025.1, you can leave it blank to use the bundled Python.
Internet, GPU, disk and paths
- Internet needed once: only while Setup Environment downloads the dependencies from PyPI; running clustering afterwards needs no internet.
- No GPU required: everything is pure CPU (pure wheels on cp310, no CUDA).
- No WSL and no external application are needed.
- Install location: the venv is built inside the installed plugin code directory, i.e.
%LOCALAPPDATA%\comet\<Dragonfly version>\pythonUserExtensions\GenericMenuItems\ClustersPlotter\venv. Reinstalling or updating the plugin code keeps that venv (it is never clobbered). - Download size: depends on the wheels for scikit-learn, scipy, numpy, matplotlib, umap-learn and hdbscan (typically on the order of tens to a couple hundred MB); the exact size varies with the base Python's wheels, so no precise figure is given here.
Base Python and fallback if setup fails
On Dragonfly 2027.1, set Base Python to a python.org Python 3.12, 3.13 or 3.14 executable. On 2025.1, you can leave it blank to use the bundled Python.
If Setup Environment fails, the panel log prints the full traceback. The usual causes are no internet access to PyPI on the first build, or the chosen base Python having no matching pre-built wheel. Make sure PyPI is reachable, or switch Base Python to another 3.10+ interpreter and retry.
5. Interface Guide
The panel is a dockable floating window, laid out top to bottom in the following groups. Each control is described below, matching the code exactly:
Input MultiROI
- MultiROI dropdown: lists the MultiROIs in the current session that carry measurement scalar slots. Each entry reads "title (N labels, M slots)" -- its label count and slot count; a currently selected object is listed first. If none carry measurements, it shows "(no MultiROI with measurements - create one first)".
- Refresh button: rescans the session and updates the MultiROI dropdown.
Feature scalar slots (tick which to cluster on)
- Slot list: a checkbox list of every scalar slot on the selected MultiROI (showing each measurement's description). All ticked by default. Tick the measurements you want to use as clustering features.
- Select all / Select none buttons: tick or untick every slot at once.
Clustering parameters
- Standardize features (StandardScaler) checkbox: zero-mean, unit-variance per feature. Checked (on) by default. Recommended when slots have different units/scales.
- Reducer dropdown: UMAP / t-SNE / PCA, default UMAP. The 2D embedding used both for the scatter and as the space clustering runs in.
- Clusterer dropdown: KMeans / HDBSCAN, default KMeans.
- KMeans n_clusters spinbox: target number of KMeans clusters, range 1-50, default 3. Editable only when Clusterer is KMeans.
- HDBSCAN min_cluster_size spinbox: the smallest group of labels that counts as a cluster, range 2-1000, default 5; smaller groups become noise (-1). Editable only when Clusterer is HDBSCAN.
Switching the Clusterer dropdown automatically enables/disables the matching spinbox: with KMeans only n_clusters is editable, with HDBSCAN only min_cluster_size is editable.
Environment (clustering venv)
- On Dragonfly 2027.1, set Base Python to a python.org Python 3.12, 3.13 or 3.14 executable. On 2025.1, you can leave it blank to use the bundled Python.
- Status label: shows whether the environment is ready -- "Ready: <venv python path>" when set up, otherwise a prompt to click Setup Environment first.
Action buttons and output area
- Setup Environment button: builds the venv and installs dependencies (one time).
- Cluster Measurements button: runs clustering with the current MultiROI, ticked slots and parameters.
- Summary label: after a run, shows a one-line summary (sample count, feature count, the reducer/clusterer actually used, number of clusters, number of noise labels).
- Log text box (read-only): shows progress and results, including the new scalar-slot index written back and the saved scatter PNG path.
6. Usage Steps
Input requirement: a MultiROI that already has per-label measurements -- that is, at least one scalar slot. If the MultiROI has no measurement slots, the plugin reports "This MultiROI has no scalar (measurement) slots. Compute per-label measurements first.", so compute per-label measurements on it in Dragonfly beforehand.
End-to-end workflow
1. Open Prototype Apps ▸ Cluster Measurements (UMAP/HDBSCAN)....
2. (First time) if Status shows not ready, click Setup Environment and wait for the log to read "Environment ready: ...".
3. Pick the target MultiROI in the MultiROI dropdown (click Refresh if it is not listed, and make sure it has measurement slots).
4. In Feature scalar slots, tick the measurements to cluster on (use Select all / Select none to toggle quickly).
5. Set parameters as needed: Standardize (on by default), Reducer (UMAP by default), Clusterer (KMeans by default); set n_clusters (default 3) for KMeans or min_cluster_size (default 5) for HDBSCAN.
6. Click Cluster Measurements to start; watch progress in the log.
7. What you get: on completion, the plugin writes each label's cluster id back as a NEW MultiROI scalar slot (described as "Cluster id"); the log reports the new slot index and the scatter PNG path, and the summary label reports sample/feature/cluster statistics.
8. Back in Dragonfly, color the MultiROI by this new "Cluster id" slot to see the groups; open the saved scatter PNG to view the 2D distribution.
When there are too few samples (labels) or an optional library is unavailable, the plugin falls back automatically: UMAP / t-SNE fall back to PCA, and HDBSCAN falls back to KMeans. The summary's "reducer_used / clusterer_used" faithfully reflect what was actually used, which may differ from what you chose.
7. Parameter Reference
Parameter | Default | Description |
MultiROI | first available in session | The input multi-label ROI; must carry measurement scalar slots (per-label measurements). |
Feature scalar slots | all ticked | Which scalar slots to use as clustering features; each ticked slot is one column of the feature matrix. Tick at least one. |
Standardize features | on (checked) | Zero-mean, unit-variance per feature (StandardScaler); recommended when slots have different units/scales. |
Reducer | UMAP | The 2D embedding method: UMAP / t-SNE / PCA. Falls back to PCA when samples are too few or the library is unavailable. |
Clusterer | KMeans | Clustering algorithm: KMeans (fixed count) or HDBSCAN (density, can produce noise). Falls back to KMeans when HDBSCAN is unavailable. |
KMeans n_clusters | 3 | Target number of KMeans clusters, range 1-50. Applies only to KMeans; the effective count is capped at the sample count. |
HDBSCAN min_cluster_size | 5 | Smallest group of labels that counts as a cluster, range 2-1000; smaller groups are labelled noise (-1). Applies only to HDBSCAN. |
Base Python | Blank on 2025.1. External Python path on 2027.1. | Base interpreter for building the compute venv; can be an absolute path or a launcher command like |
Additional notes: t-SNE requires at least 5 samples to run (otherwise it falls back to PCA), and its perplexity is chosen automatically from the sample count; UMAP's n_neighbors is also chosen automatically (capped at 15). NaN / inf values in the feature matrix are cleaned to 0 before computing. These are internal adaptive behaviors that need no manual tuning.
8. Outputs
A successful clustering run produces the following:
- New MultiROI scalar slot "Cluster id": each label (1..N; background label 0 is excluded) gets an integer cluster id (>=0 for a cluster; -1 for noise, only possible with HDBSCAN). The new slot is appended after the MultiROI's existing scalar slots. After writing, the plugin sets the slot's window/range and publishes it, so the new slot appears in Dragonfly immediately.
- 2D scatter PNG: a 2D scatter colored by cluster (drawn with matplotlib), with noise points shown as grey "x" markers and each cluster in a distinct color; a legend is included when there are at most 12 clusters. The file is saved in a temporary job directory and its full path is printed to the log.
- Summary: a one-line text summary with the sample count, feature count, the reducer actually used, the clusterer actually used, and the number of clusters and noise labels.
How to view the results
1. Select the MultiROI in Dragonfly and switch its coloring scalar slot to the newly written "Cluster id" slot -- the different groups are then colored by value and can be distinguished in the 2D/3D views.
2. Open the scatter PNG at the path shown in the log to see how well-separated the groups are in 2D.
3. Read the summary line to judge whether the clustering is reasonable (e.g. whether the cluster count matches expectations, whether there is too much noise), and re-run with adjusted parameters if needed.
The cluster id itself has no physical "size/quality" meaning -- it is only a group label. To interpret what each group represents (morphology or composition), analyze each group's original measurements (volume, sphericity, etc.).
9. FAQ and Troubleshooting
Q: The MultiROI dropdown is empty / shows "no MultiROI with measurements".
A: The session has no MultiROI with measurement scalar slots. Compute per-label measurements on your MultiROI in Dragonfly first (to create scalar slots), then click Refresh in the panel.
Q: Cluster Measurements errors with "This MultiROI has no scalar (measurement) slots".
A: The selected MultiROI carries no measurement scalar slots. This plugin clusters existing measurements; it does not compute volume/sphericity itself -- compute per-label measurements in Dragonfly first.
Q: It says the environment is not set up.
A: First use requires Setup Environment (internet needed once). If you already ran it but it still reports not ready, check the log for the error; you can set Base Python to another 3.10+ Python and retry.
Q: I chose UMAP / HDBSCAN, but the summary shows reducer_used / clusterer_used as PCA / KMeans?
A: That is the expected automatic fallback. When there are too few samples (labels), or umap-learn / hdbscan is unavailable in the environment, UMAP/t-SNE fall back to PCA and HDBSCAN falls back to KMeans. If you truly need UMAP/HDBSCAN, make sure Setup Environment installed those libraries and that there are enough labels.
Q: HDBSCAN labels most of the labels as noise (-1).
A: The data has no sufficiently dense groups, or min_cluster_size is set too large. Lower min_cluster_size, or switch to KMeans with a fixed cluster count; you can also try toggling standardization or changing the reducer.
Q: Setup Environment fails to download the dependencies.
A: Usually PyPI is unreachable (network/proxy) or the chosen base Python has no matching wheel. Make sure PyPI is reachable, or set Base Python to another CPython 3.10+ interpreter and retry.
10. Notes and Known Limitations
- Clusters existing measurements only: the plugin does not compute the measurements; the input MultiROI must already carry per-label measurement scalar slots.
- Background excluded: label 0 (background) does not participate; cluster ids are written back for labels 1..N in order.
- Result written as a new slot: each run appends a new "Cluster id" scalar slot and never overwrites existing measurements; repeated runs accumulate multiple new slots.
- Automatic fallback cannot be disabled: with too few samples or a missing library it silently falls back to PCA/KMeans, so trust the summary's reducer_used / clusterer_used.
- 2D embedding: reduction is fixed to 2D (for plotting and clustering); no higher-dimensional embedding option is offered.
- Internet needed once: only during Setup Environment; afterwards it runs offline. No GPU, no WSL, no external application required.
- Randomness: a fixed random seed is used for reproducibility, but methods like t-SNE / UMAP are sensitive to parameters and sample size, so results can vary across datasets.
- Menu discovery: after enabling/disabling or installing, Dragonfly must be fully restarted before the menu appears or disappears.
11. References
- scikit-learn (PCA / t-SNE / KMeans / StandardScaler): https://scikit-learn.org
- UMAP (umap-learn): https://umap-learn.readthedocs.io
- HDBSCAN (hdbscan): https://hdbscan.readthedocs.io
- matplotlib: https://matplotlib.org
- NumPy: https://numpy.org
- For online installation and plugin activation, see Chapter 3.