半自动化 QuPath 工作流 · 多重免疫荧光全切片图像分析
🔬 面向肿瘤-神经-免疫微环境研究
- 🧪 DAPI 细胞核分割
- 🏷️ 基于标记物的细胞分类 (CD3·CK)
- 📏 参考区域归一化与阈值估计
- 🧠 神经区域组织 (分割或标注整理)
- 📐 距离测量
- 📤 CSV 与 GeoJSON 导出
- 🛠️ 层级修复工具
本项目专为多重免疫荧光全切片图像的计算病理学工作流设计,重点分析神经周围浸润 (PNI) 区域的肿瘤-神经-免疫微环境。
工作流为半自动流程,需要手动绘制标注并进行视觉质控。
在 MxIF 全切片图像分析中:
- 固定阈值容易受到批次效应与自发荧光影响
- annotation 与 hierarchy 经常混乱
- 神经区域与免疫区域关系复杂
- 下游空间统计需要结构化导出
本工具包的目标是:
将病理人工标注与可复现的计算特征提取连接起来。
| 项目 | 说明 |
|---|---|
| QuPath | v0.5.1 |
| 图像 | 已校准的 MxIF 全切片图像 |
| 脚本引擎 | 启用 Groovy 脚本 |
| 生物学靶标 | 默认通道名 |
|---|---|
| 细胞核 | DAPI / DAPI (C1) |
| 免疫标记 | Opal 620 |
| 肿瘤标记 | Opal 780 (C6) |
| 神经标记 | Opal 480 |
| 类名 | 含义 |
|---|---|
PNI- |
PNI 阴性区域 |
PNI+: Immune Responsive |
PNI 阳性伴免疫应答 |
PNI+: Immune Excluded |
PNI 阳性伴免疫排斥 |
| 名称 / 类 | 含义 |
|---|---|
Normalization Patch |
用于强度归一化或质控的区域 |
dark_ref |
暗场 / 背景参考区域 |
bright_ref |
亮场 / 阳性参考区域 |
nerve_regions |
神经区域标注 |
flowchart LR
A[手动标注] --> B[归一化 / 阈值锚点]
B --> C[DAPI 细胞分割]
C --> D[基于标记物的细胞分类]
D --> E[神经区域组织]
E --> F[距离测量]
F --> G[CSV 与 GeoJSON 导出]
G --> H[下游空间分析]
建议始终对分割与分类结果进行可视化检查。
至少创建:
PNI-PNI+: Immune ResponsivePNI+: Immune Excluded
先运行:
scripts/02_cell_segmentation/00_segment_cells_selected_annotations.groovy
用于调试参数。
运行:
scripts/03_cell_classification/01_classify_cd3_cells_selected_annotations.groovy
运行:
scripts/06_export/02_export_project_cell_measurements_batch.groovy
在 Python / R 中进行空间统计分析。
QuPath-MxIF-Analysis-Toolkit/
├── README.md
├── LICENSE
├── .gitignore
├── docs/
│ ├── annotation_convention.md
│ ├── channel_convention.md
│ ├── output_schema.md
│ ├── troubleshooting.md
│ └── screenshots/
├── scripts/
│ ├── 00_setup/
│ ├── 01_normalization/
│ ├── 02_cell_segmentation/
│ ├── 03_cell_classification/
│ ├── 04_nerve_region/
│ ├── 05_spatial_measurement/
│ ├── 06_export/
│ ├── 99_debug_utils/
│ └── experimental/
标注层级工具、统计框数、建立神经区域的父-子关系。
利用参考区域估算显示锚点与自适应阈值。
基于 DAPI 的细胞分割。
👉 建议先在选中标注上运行以调试参数,再批量运行。
按标记强度分类:
immune_celltumor_cellunclassified/none
神经区域分割与层级整理。
计算细胞到神经区域标注的距离。
导出细胞级测量值与标注级几何信息。
| 输出文件 | 描述 |
|---|---|
export_cells_by_annotation_*.csv |
细胞级测量值,按父级 PNI 分组 |
geojson_<annotation_id>.geojson |
每个标注关联的神经区域几何 |
all_shapes.json |
全部导出的标注几何 |
all_cells.csv |
全部导出的细胞测量值 |
用于调试与清理的脚本。
- 绘制或加载目标 PNI 标注。
- (可选)绘制
Normalization Patch,dark_ref和bright_ref。 - 在选中标注上运行细胞分割,进行参数调试。
- 对所有 PNI 标注批量运行细胞分割。
- 运行基于标记物的细胞分类。
- 整理或分割神经区域。
- 计算距离到标注的测量值。
- 导出 CSV 与 GeoJSON。
- 在 Python、R 或其他工具中进行下游分析。
| Document | Description |
|---|---|
docs/annotation_convention.md |
Annotation naming and hierarchy rules |
docs/channel_convention.md |
Recommended image channel naming |
docs/output_schema.md |
Export CSV / GeoJSON schema |
docs/troubleshooting.md |
Common workflow issues |
- 🔍 始终对分割与分类结果进行可视化检查。
- 📊 阈值依赖于具体数据集,需按需调整。
- 📛 通道名称可能需要根据您的图像数据修改。
- 🧪 本工具包适用于 QuPath v0.5.1,其他版本未测试。
- 🧬 这是一个研究工作流,并非临床诊断流水线。
MIT License.
如果您的研究受益于本工具包,请引用此仓库。
A semi-automated QuPath workflow for multiplex immunofluorescence whole-slide image analysis
🔬 Designed for tumor-nerve-immune microenvironment research around perineural invasion
- 🧪 DAPI-based cell / nucleus segmentation
- 🏷️ Marker-based immune and tumor cell classification
- 📏 Reference-region-based normalization and threshold estimation
- 🧠 Nerve region segmentation or annotation organization
- 📐 Spatial distance-to-annotation measurement
- 📤 CSV & GeoJSON export
- 🛠️ QuPath hierarchy repair utilities
This project is designed for computational pathology workflows involving multiplex immunofluorescence (MxIF) whole-slide images, with a focus on the tumor-nerve-immune microenvironment surrounding perineural invasion (PNI) regions.
The workflow is semi-automated and assumes:
- manual pathological annotations
- iterative parameter tuning
- visual quality control throughout the analysis
MxIF whole-slide image analysis often suffers from:
- batch effects and autofluorescence contamination
- inconsistent annotation hierarchy organization
- complex tumor-immune-nerve spatial relationships
- limited support for downstream spatial feature extraction
Many pathology workflows focus only on segmentation or classification, but real computational pathology pipelines also require:
- annotation management
- hierarchy repair
- reproducible export formats
- spatial distance measurements
- downstream analysis compatibility
This toolkit aims to bridge:
manual pathological annotation and reproducible computational feature extraction.
| Item | Description |
|---|---|
| QuPath | v0.5.1 |
| Images | Calibrated MxIF whole-slide images |
| Script engine | Groovy enabled |
| Biological target | Default channel |
|---|---|
| Nuclei | DAPI or DAPI (C1) |
| Immune marker | Opal 620 |
| Tumor marker | Opal 780 (C6) |
| Nerve marker | Opal 480 |
| Class | Meaning |
|---|---|
PNI- |
PNI-negative region |
PNI+: Immune Responsive |
PNI-positive region with immune infiltration |
PNI+: Immune Excluded |
PNI-positive region with immune exclusion |
| Name / Class | Meaning |
|---|---|
Normalization Patch |
Region for intensity normalization or QC |
dark_ref |
Dark/background reference region |
bright_ref |
Bright/positive reference region |
nerve_regions |
Nerve region annotations |
flowchart LR
A[Manual Annotation] --> B[Normalization / Threshold Anchors]
B --> C[DAPI Cell Segmentation]
C --> D[Marker-based Cell Classification]
D --> E[Nerve Region Organization]
E --> F[Spatial Distance Measurement]
F --> G[CSV & GeoJSON Export]
G --> H[Downstream Spatial Analysis]
Visual inspection of segmentation and classification results is strongly recommended.
Create at least:
PNI-PNI+: Immune ResponsivePNI+: Immune Excluded
Optional helper annotations:
Normalization Patchdark_refbright_refnerve_regions
First run:
scripts/02_cell_segmentation/00_segment_cells_selected_annotations.groovy
for parameter tuning and visual inspection.
After confirming segmentation quality, run the batch workflow on all target annotations.
Run:
scripts/03_cell_classification/01_classify_cd3_cells_selected_annotations.groovy
to classify immune-positive cells.
Use the nerve-region organization scripts to:
- move nerve annotations into hierarchy
- repair parent-child relationships
- prepare downstream spatial analysis
Experimental segmentation scripts are provided under:
/scripts/experimental/
Run:
scripts/06_export/02_export_project_cell_measurements_batch.groovy
to export combined project-level measurements.
Perform downstream analysis in:
- Python
- R
- GeoPandas
- spatial statistics workflows
- machine learning pipelines
QuPath-MxIF-Analysis-Toolkit/
├── README.md
├── LICENSE
├── .gitignore
├── docs/
│ ├── annotation_convention.md
│ ├── channel_convention.md
│ ├── output_schema.md
│ ├── troubleshooting.md
│ └── screenshots/
├── scripts/
│ ├── 00_setup/
│ ├── 01_normalization/
│ ├── 02_cell_segmentation/
│ ├── 03_cell_classification/
│ ├── 04_nerve_region/
│ ├── 05_spatial_measurement/
│ ├── 06_export/
│ ├── 99_debug_utils/
│ └── experimental/
Utilities for:
- annotation hierarchy organization
- counting-box preparation
- parent-child relationship repair
- nerve-region hierarchy management
Reference-region-based normalization and threshold estimation.
This module estimates:
- display anchors
- percentile-based intensity ranges
- adaptive threshold references
for more stable MxIF analysis.
DAPI-based nucleus/cell segmentation.
👉 Recommended workflow:
- run on selected annotations first
- visually inspect segmentation quality
- then run batch analysis
Marker-intensity-based classification.
Current supported classes include:
immune_celltumor_cellunclassifiednone
Nerve-region segmentation and hierarchy organization.
Distance-to-annotation measurements for downstream spatial analysis.
Typical downstream applications:
- immune infiltration analysis
- tumor-nerve distance analysis
- graph-based spatial modeling
- PNI feature engineering
Export cell-level measurements and annotation geometries.
| Output file | Description |
|---|---|
export_cells_by_annotation_*.csv |
Cell measurements grouped by parent PNI annotation |
geojson_<annotation_id>.geojson |
Nerve geometries associated with each annotation |
all_shapes.json |
Exported annotation geometries |
all_cells.csv |
Exported cell measurements |
combined_cell_measurements.csv |
Combined project-level measurements |
Scripts for cleanup, hierarchy repair, and debugging.
- delete objects
- move hierarchy relationships
- reset classifications
Use carefully.
- Draw or import PNI annotations.
- (Optional) Draw normalization and reference annotations.
- Run segmentation on selected annotations for tuning.
- Run batch segmentation on all target PNI annotations.
- Perform marker-based cell classification.
- Organize or segment nerve regions.
- Compute spatial distance measurements.
- Export CSV and GeoJSON outputs.
- Perform downstream spatial analysis.
| Document | Description |
|---|---|
docs/annotation_convention.md |
Annotation naming and hierarchy rules |
docs/channel_convention.md |
Recommended image channel naming |
docs/output_schema.md |
Export CSV / GeoJSON schema |
docs/troubleshooting.md |
Common workflow issues |
- Always visually inspect segmentation and classification results.
- Thresholds are dataset-dependent and require tuning.
- Channel names may need adjustment for different datasets.
- Experimental modules are not guaranteed to be robust.
- Tested primarily on QuPath v0.5.1.
- This is a research workflow, not a clinical diagnostic pipeline.
MIT License.
If this toolkit contributes to your research, please cite this repository.


