Computational pipeline for quantifying CD4+ T helper cells in whole-slide fluorescence microscopy images of ulcerative colitis (UC) tissue. Segments nuclei from DAPI channel images using Cellpose-SAM, measures CD4 fluorescence intensity per nucleus, and classifies cells as CD4+ or CD4− using two thresholding methods.
Data & Results Notice: This project was conducted using patient tissue samples provided by a clinical collaborator. Raw data, processed outputs, and derived figures are not included in this repository and will not be shared publicly prior to official publication. Results are available upon request for academic review purposes.
Ulcerative colitis is a chronic inflammatory bowel disease. This pipeline quantifies CD4+ immune cell infiltration across three disease states from a single patient:
| Condition | Description |
|---|---|
| Control | Healthy tissue — low immune activity, regular crypt morphology |
| Inflammation | Active disease — dense CD4+ infiltration, compressed crypts |
| Remission | Partial resolution — recovering architecture, reduced immune cells |
DAPI image ──► Cellpose-SAM ──► Nuclear masks ──► regionprops (CD4 intensity) ──► Threshold ──► CD4+ / CD4−
(segmentation) (measurement) (classification)
Segmentation — Cellpose-SAM (cpsam model) segments nuclei from the DAPI channel. DAPI is used because it produces solid nuclear fills, unlike CD4's ring-shaped membrane staining.
Measurement — scikit-image regionprops_table measures mean CD4 fluorescence intensity within each DAPI-derived nuclear mask.
Classification — Two methods compared:
- Otsu thresholding — automatic, per-condition cutoff that minimizes within-class variance
- Gaussian Mixture Model (GMM) — fits two Gaussian components (background + signal) per condition
Results figures and quantification outputs are omitted from this repository pending publication and clinical data sharing approval. The pipeline successfully produced segmentation masks, per-nucleus CD4 intensity measurements, and CD4+ classifications across all three conditions. Both thresholding methods confirmed the expected biological gradient across the disease spectrum.
- Per-condition thresholding — inter-slide intensity variation (staining differences) makes a single global threshold unreliable. Each condition's threshold is derived from its own distribution.
- Single outer loop — processes one condition at a time for memory management with large (~80M pixel) 16-bit TIFF images.
tifffileover OpenCV — OpenCV silently converts 16-bit to 8-bit, destroying intensity data.tifffilepreserves full dynamic range.- Batch visualization —
plt.savefig()+plt.close()instead ofplt.show()so the pipeline runs uninterrupted.
- Inflammation undersegmentation — dense cell packing causes Cellpose to merge adjacent nuclei, underestimating the true count
- No cross-condition intensity normalization — per-condition thresholding is a workaround, not a solution
- Single patient (n=1 per condition) — results are descriptive; statistical generalization requires more samples
- Unimodal distributions — neither Otsu nor GMM is operating in its ideal bimodal scenario
UC_Cellpose_Project/
├── data/ # Raw 16-bit TIFF images (not tracked)
│ ├── control/
│ ├── inflammation/
│ └── remission/
├── notebooks/
│ └── pipeline.ipynb # Main analysis notebook
├── outputs/ # Generated figures and CSVs (not tracked)
├── scripts/ # Utility scripts
├── docs/ # Documentation (figures omitted pending publication)
├── .gitignore
└── README.md
- Python 3.10 (conda env:
uc_cellpose) - Cellpose 4.0.9 (Cellpose-SAM /
cpsammodel) - NVIDIA RTX 4070, CUDA 12.6
- scikit-image, scikit-learn, pandas, matplotlib, seaborn, tifffile
- Stringer, C., & Pachitariu, M. (2025). Cellpose-SAM. bioRxiv. doi:10.1101/2025.04.28.651001
- Stringer, C., Wang, T., Michaelos, M., & Pachitariu, M. (2021). Cellpose: a generalist algorithm for cellular segmentation. Nature Methods, 18, 100–106.