Comprehensive benchmarking of vessel segmentation pipelines for histology images with DAB immunostaining.
This repository compares three vessel segmentation methods on histological images with brown DAB (diaminobenzidine) immunostaining marking endothelial cells:
- VeSpA - Color-based vessel segmentation using CMYK decomposition
- VeSpA+SAM (Hybrid) - Novel hybrid approach combining color priors with foundation models
- SAM - Segment Anything Model with automatic mask generation
- YOLOv8-seg - Pre-trained object detection and segmentation
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
mkdir -p models
mv sam_vit_b_01ec64.pth models/pip install -r requirements.txtpython evaluation/benchmark.py --all-categoriesThis will:
- Process all images in
datasets/images/ - Compare all four methods
- Generate metrics (Dice, IoU, Precision, Recall)
- Create comparison plots in
results/metrics/ - Save predictions in
results/prediction/
Approach: Color-based segmentation using CMYK decomposition
Key Steps:
- Convert BGR → CMYK color space
- Extract Yellow channel (inverse of brown stain)
- Apply Otsu threshold
- Morphological operations (blur, close, dilate, erode)
Advantages:
- Domain-specific (targets brown immunostain)
- Fast and deterministic
- No model weights required
Limitations:
- Sensitive to morphological parameter tuning
- Sometimes imperfect boundary definition
Approach: Combines color priors with foundation model refinement
Key Steps:
- Stain Detection (VeSpA): Extract brown stain using CMYK + Otsu
- Prompt Generation: Find connected components, compute centroids
- SAM Refinement: Use centroids as point prompts to SamPredictor
- Post-processing: Combine masks, remove artifacts
Advantages:
- ✓ Domain-aware (targets brown stain)
- ✓ Boundary refinement (SAM correction)
- ✓ Reduced false positives (constrained to stain regions)
- ✓ Handles staining variability
Expected Improvements over SAM alone:
- Higher precision (fewer non-vessel detections)
- Better boundary accuracy
- Robustness to stain intensity variations
Expected Improvements over VeSpA alone:
- Superior boundary definition
- Less sensitive to morphological parameters
- Foundation model reliability
Approach: Foundation model with automatic mask generation
Key Steps:
- Uniform 16×16 grid of prompt points
- SAM prediction at each point
- Filtering by IoU and stability scores
- Mask combination
Advantages:
- Automatic (no prompting required)
- Detects diverse objects
- Strong generalization
Limitations:
- Not histology-aware
- Many false positives from non-vessel structures
- Grid-based sampling may miss small vessels
Approach: Pre-trained instance segmentation
Key Steps:
- Object detection + segmentation head
- Non-maximum suppression
- Mask refinement
Advantages:
- Fast inference (nano model)
- Well-optimized
Limitations:
- Trained on general objects
- May not generalize well to histology
pipelines/
├── sam/
│ └── run_sam.py # Automatic SAM segmentation
├── yolo/
│ └── run_yolo.py # YOLOv8-seg segmentation
├── VeSpA/
│ └── Segmentation + Measurements.py # Color-based segmentation
└── hybrid/
├── __init__.py
└── run_vespa_sam.py # Novel hybrid approach (NEW)
evaluation/
├── benchmark.py # Main benchmarking script
└── metrics.py # Metric computation
datasets/
├── images/ # Input histology images
├── groundtruth/ # Manual annotations
└── masks/ # Predicted masks
All pipelines support configuration via environment variables:
# SAM configuration
export SAM_MODEL_TYPE="vit_b" # vit_b, vit_l, vit_h
export SAM_MAX_DIM="1024" # Input resize dimension
export SAM_CHECKPOINT="models/sam_vit_b_01ec64.pth"
# YOLO configuration
export YOLO_SEG_WEIGHTS="models/yolov8n-seg.pt"
# VeSpA/Hybrid configuration (morphological parameters)
export BLUR_KERNEL="5"
export CLOSING_KERNEL="5"All methods evaluated on:
- Dice Coefficient: 2·|A∩B| / (|A| + |B|)
- IoU (Intersection over Union): |A∩B| / |A∪B|
- Precision: TP / (TP + FP)
- Recall: TP / (TP + FN)
- Runtime: Seconds per image
Results saved to:
results/metrics/results_cat2.csv- Per-image metrics (default: intersection GT)results/metrics/summary_cat2.csv- Mean metrics per modelresults/metrics/runtime_summary_cat2.csv- Runtime comparisonresults/metrics/results_all_categories.csv- All categories combinedresults/metrics/*.png- Comparison plots
Predictions saved to:
results/prediction/{model_name}/*_pred.png- Binary predictionsresults/prediction/{model_name}/*_overlay.png- Overlay visualization
See TECHNICAL_NOTES.md for detailed explanation of:
- SAM automatic vs. prompt-guided segmentation
- Why histology-specific prompts improve segmentation
- Hybrid pipeline algorithm description
- Expected advantages and improvements
If you use this benchmarking repository or the hybrid VeSpA+SAM pipeline, please cite:
@misc{vespa_benchmark_2024,
title={VeSpA Benchmarking: Hybrid Foundation Model and Color-Prior Vessel Segmentation},
author={[Your Name]},
year={2024},
howpublished={GitHub},
url={https://github.com/[your-repo]/VeSpA_benchmarking}
}- Python 3.8+
- PyTorch (CPU or CUDA)
- OpenCV
- NumPy, Pandas, Matplotlib
- segment-anything
- ultralytics (YOLO)
- scikit-image
See requirements.txt for full dependency list.
[Add appropriate license]
For questions or issues, please open an issue on GitHub.