Classify MultiROI Labels(MultiROI 标签自动分类)
Classify MultiROI Labels - User Manual
Dragonfly Prototype Apps · Classify MultiROI Labels...
版本 Version 1.0 · 2026-07-26
第一部分 中文手册
目录
1. 简介
2. 功能特点
3. 三种分类模式
4. 使用步骤
5. 环境需求
6. 提示与注意
1. 简介
本插件对一个 MultiROI 里的每一个 label(每个 label 通常对应图像里的一个颗粒 / 物体)自动分类:先用配套的灰度强度 Channel 逐 label 提取大量图像特征(radiomics),再把每个 label 归入 1..N 组,并把分组编号作为一个名为 “Classification Group” 的 scalar value slot(标量值槽) 写回该 MultiROI,同时按分组着色显示。
特征提取用 Dragonfly 自带的 pyradiomics:一阶灰度统计(first-order)+ 形状 / 形态(shape)+ GLCM / GLRLM / GLSZM / GLDM / NGTDM 纹理,约 90+ 个特征;提取后做标准化 + PCA 降噪,再聚类 / 分类。
适用场景:一张图里有几百个颗粒(已用分割得到 MultiROI),肉眼能按亮度 / 纹理 / 形状 / 大小区分出 N 种类型,希望自动把每个颗粒归类并上色分组。例如矿物 / 岩石薄片的物相分类、粉末颗粒分型、孔隙 / 夹杂物分型、细胞 / 晶粒按形态分型等。
全程在 Dragonfly 进程内运行,用其自带的 scikit-learn / scikit-image / pyradiomics / SimpleITK——无需 venv、无需联网、无需 GPU。
2. 功能特点
- 逐 label 特征提取:可勾选三个特征族——一阶灰度、形状 / 形态、纹理(GLCM/GLRLM/GLSZM/GLDM/NGTDM)。二维、三维数据均可(二维自动使用 shape2D 纹理)。
- 三种分类方式:无监督 K-Means(手动指定 N,或 Auto 建议 N)、半监督随机森林(在几个已知类型的 label 上打标签后训练预测)、以及三特征方案对比(同一 N 下用三种不同 radiomics 特征子集各聚一次,写出三个标量槽供对比)。
- 多种聚类算法:K-Means、Gaussian Mixture(高斯混合)、Agglomerative(层次聚类)。
- 特征方案(Feature scheme):可只用 全部特征 / 仅形状 / 仅一阶强度 / 仅纹理 / 形状+强度 / 强度+纹理——选一个贴合你的颗粒“差异来源”的子集,是提升聚类质量最有效的杠杆。
- 分组编号排序:分组 1..N 可按 簇大小 / 平均灰度 / 体积 排序,便于解释。
- 离群检测:可选把离聚类中心过远(距离 > 均值 + z·标准差)的 label 归为 group 0(未分类 / 离群)。
- 标量槽管理器:列出该 MultiROI 上所有 scalar slot,可切换显示(按某个分类着色)或删除不想保留的分类。
- 结果导出:可导出 每 label 的特征 + 分组 CSV,以及一张 PCA 散点图(按分组着色)。
3. 三种分类模式
1) 无监督 K-Means(默认)
手动设定分组数 N,或点 “Auto — suggest N” 让插件用三种聚类有效性指标(silhouette / Calinski-Harabasz / Davies-Bouldin)共识投票建议一个 N,并显示各 N 的曲线。这是一个建议——若已知类型数,请自行确认后再分类。
2) 三特征方案对比 → 三个标量槽
在 “Compare 3 feature schemes” 里选三个特征方案(默认 全部 / 形状+强度 / 纹理),插件用同一 N 各聚一次,写出 “Classification-Radiomics-K-Means-1/2/3” 三个标量槽。用下方标量槽下拉框逐一查看、留下最合适的、删掉其余的。
3) 半监督(打标签示例)
为每个组各挑几个已知类型的 label 做示例:在 Dragonfly 里选中这些 label 后点 “Add Dragonfly selection → selected group”,或在表格里直接填 label ID。插件用随机森林训练并对全部 label 预测(并给出交叉验证准确率)。至少要在 2 个组各标 1 个、共标 ≥2 个 label。
4. 使用步骤
1. 在 Prototype Apps ▸ Measurements & Analysis ▸ Classify MultiROI Labels... 打开插件。
2. 标签页 1「Input & Features」:点 Refresh lists,选择一个 Intensity Channel(灰度强度 Channel) 和一个与之同网格的 MultiROI(每个 label 一个颗粒)。
3. 勾选要用的 Feature families(特征族)——First-order / Shape / Texture,点 Extract features 提取特征(大 MultiROI 会逐 label 进行,可看日志进度)。
4. 标签页 2「Classify & Write」:在 Mode 选无监督或半监督;无监督下设 N(或 Auto)、算法、特征方案、编号排序、是否标离群。
5. 点 Classify 得到每 label 的分组,界面会显示各组的 label 数、silhouette / CV 准确率等。
6. 点 Write groups → MultiROI 把 “Classification Group” 标量槽写回 MultiROI——之后 MultiROI 即按分组着色。
7. (可选)点 Save features + groups CSV… 导出 CSV,或 Save PCA plot… 导出 PCA 散点图。
8. (可选)用底部 标量槽管理器:Slot 下拉选一个槽,Show / color by this 切换显示,Delete slot 删除不想要的分类。
5. 环境需求
- 输入:一个灰度强度 Channel + 一个与之同网格的 MultiROI(每个 label 一个颗粒)。二维、三维均可。
- 无需环境安装:进程内运行,直接用 Dragonfly 自带的 numpy / scipy / scikit-learn / scikit-image / pyradiomics / SimpleITK。
- 无需 GPU、无需联网、无需管理员权限。
- 安装:运行
python install_label_classifier_plugin.py(会安装到本机每个 Dragonfly 版本),然后完全重启 Dragonfly 才能看到菜单项。
6. 提示与注意
- 特征方案是质量的关键杠杆:不同颗粒类型往往在“形状 / 亮度 / 纹理”其中一维上分得最开。若默认“全部特征”分得不理想,用三特征方案对比找出最合适的子集。
- Auto 给的 N 只是建议:它易在高度相关的 radiomics 特征上偏向粗略的 k=2。已知类型数时优先手动设 N(最稳),或用半监督(最贴合你自己的判定标准)。
- 太小 / 退化的 label 可能无法计算纹理特征,会被跳过(提取结果里会提示跳过的数量),这些 label 不参与分类。
- 离群组 0:勾选“Flag outliers as group 0”后,离簇心过远的 label 归为 0(未分类),z 值越小归为离群的越多。
- 重活(特征提取 / 聚类)都在后台线程运行,界面按钮会临时禁用;请看底部日志了解进度。
Part II English Manual
Contents
1. Introduction
2. Features
3. Classification modes
4. How to use
5. Requirements
6. Tips & notes
1. Introduction
This plugin automatically classifies every label in a MultiROI (each label is usually one particle / object in the image): using a paired intensity Channel, it extracts many per-label image features (radiomics), assigns each label to a group 1..N, and writes the group id back as a scalar-value slot named "Classification Group" on the MultiROI, coloring the MultiROI by group.
Features are extracted with Dragonfly's bundled pyradiomics: first-order intensity + shape / morphology + GLCM / GLRLM / GLSZM / GLDM / NGTDM texture (~90+ features). They are then standardized and PCA-denoised before clustering / classification.
Use it when an image has hundreds of particles (already segmented into a MultiROI) and the eye can tell N types apart by brightness / texture / shape / size, and you want each particle auto-classified and color-grouped: mineral / rock thin-section phase classification, powder-particle typing, pore / inclusion typing, cell / grain morphology typing, and similar.
Everything runs in-process inside Dragonfly using its bundled scikit-learn / scikit-image / pyradiomics / SimpleITK — no venv, no internet, no GPU.
2. Features
- Per-label feature extraction: pick from three feature families — first-order intensity, shape / morphology, and texture (GLCM/GLRLM/GLSZM/GLDM/NGTDM). Works on 2D or 3D data (2D uses shape2D texture automatically).
- Three ways to classify: unsupervised K-Means (manual N, or Auto to suggest N), semi-supervised RandomForest (tag a few example labels per type, then train + predict), and a 3-feature-scheme comparison (cluster three different radiomics feature subsets at the same N, writing three scalar slots to compare).
- Multiple clustering algorithms: K-Means, Gaussian Mixture, and Agglomerative clustering.
- Feature scheme: cluster on all features / shape only / first-order intensity only / texture only / shape + intensity / intensity + texture. Choosing the subset that matches how your particle types actually differ is the single biggest lever on clustering quality.
- Group numbering: groups 1..N can be numbered by cluster size / mean intensity / volume for interpretability.
- Outlier detection: optionally flag labels far from their cluster center (distance > mean + z·std) as group 0 (unclassified / outlier).
- Scalar-slot manager: lists every scalar slot on the MultiROI so you can switch which classification is displayed (color by it) or delete ones you don't want to keep.
- Exports: save a per-label features + group CSV and a PCA scatter plot (colored by group).
3. Classification modes
1) Unsupervised K-Means (default)
Set the number of groups N manually, or click "Auto — suggest N" to have the plugin suggest an N from a consensus vote of three cluster-validity indices (silhouette / Calinski-Harabasz / Davies-Bouldin), with the per-N curve shown. This is a suggestion — if you know the type count, confirm it yourself before classifying.
2) Compare 3 feature schemes → 3 scalar slots
In "Compare 3 feature schemes", pick three schemes (default: all / shape + intensity / texture). The plugin clusters at the same N with each and writes three slots named "Classification-Radiomics-K-Means-1/2/3". Use the scalar-slot dropdown below to review each, keep the best, and delete the rest.
3) Semi-supervised (tag examples)
Tag a few example labels per group: select them in Dragonfly and click "Add Dragonfly selection → selected group", or type label IDs directly into the table. The plugin trains a RandomForest and predicts all labels (reporting a cross-validation accuracy). Tag at least 2 labels across at least 2 groups.
4. How to use
1. Open it at Prototype Apps ▸ Measurements & Analysis ▸ Classify MultiROI Labels...
2. Tab 1 "Input & Features": click Refresh lists, then pick an Intensity Channel and a MultiROI on the same grid (one label per particle).
3. Tick the Feature families you want — First-order / Shape / Texture — then click Extract features (large MultiROIs are processed label by label; watch the log for progress).
4. Tab 2 "Classify & Write": choose a Mode (unsupervised or semi-supervised); for unsupervised set N (or Auto), the algorithm, feature scheme, group numbering, and optional outlier flagging.
5. Click Classify to get a group per label; the panel reports the per-group label counts, silhouette / CV accuracy, etc.
6. Click Write groups → MultiROI to write the "Classification Group" scalar slot back — the MultiROI is then colored by group.
7. (Optional) click Save features + groups CSV… to export a CSV, or Save PCA plot… for a PCA scatter plot.
8. (Optional) use the scalar-slot manager at the bottom: pick a Slot, Show / color by this to switch the displayed classification, or Delete slot to remove an unwanted one.
5. Requirements
- Input: an intensity Channel + a MultiROI on the same grid (one label per particle). 2D or 3D.
- No environment setup: runs in-process with Dragonfly's bundled numpy / scipy / scikit-learn / scikit-image / pyradiomics / SimpleITK.
- No GPU, no internet, and no administrator rights required.
- Install with
python install_label_classifier_plugin.py(deploys to every Dragonfly version on the machine), then fully restart Dragonfly to see the menu item.
6. Tips & notes
- The feature scheme is the key quality lever: different particle types usually separate best along one of shape / brightness / texture. If the default "all features" clusters poorly, use the 3-feature-scheme comparison to find the best subset.
- Auto's N is only a suggestion: with many correlated radiomics features it tends to favor a coarse k=2 split. When you know the type count, prefer setting N manually (most robust) or use semi-supervised (closest to your own criteria).
- Very small / degenerate labels where texture is undefined are skipped (the extraction result reports how many were skipped) and do not take part in classification.
- Outlier group 0: with "Flag outliers as group 0" on, labels too far from their cluster center become group 0 (unclassified); a smaller z flags more of them.
- Heavy work (feature extraction / clustering) runs on a background thread, so the buttons are temporarily disabled; watch the log at the bottom for progress.