Post-processing pipeline for converting RGB semantic segmentation outputs into object-level counts of pathological structures. The script extracts class-specific regions from a single color-coded segmentation image, applies morphological operations to merge fragmented structures, and performs connected component analysis to count individual objects.
The pipeline operates on segmentation outputs where each class is encoded using a fixed RGB color:
- Red [0, 0, 255] → Dystrophic neurites
- Green [0, 255, 0] → Tangle-bearing cell bodies
- Blue [255, 0, 0] → Neuritic plaques
For each image:
- Class-specific regions are extracted via exact RGB thresholding
- Morphological closing is applied to merge fragmented regions
- External contours are detected
- Each valid contour is counted as one object
- Results are saved as annotated images and in a CSV file
Binary masks are generated by selecting pixels that exactly match the RGB values of each class.
Morphological closing (dilation followed by erosion) is applied using class-specific kernel sizes:
| Class | Kernel Size | Purpose |
|---|---|---|
| Neurites | 1 × 1 | Minimal processing |
| Cell bodies | 80 × 80 | Merge fragmented regions |
| Plaques | 250 × 250 | Merge large fragmented structures |
These kernel sizes act as hyperparameters controlling how nearby regions are merged. They were manually tuned based on visual inspection.
- Contours are extracted and each one is treated as one object
- Small/noisy detections are filtered:
- Cell bodies & plaques: ≥ 5 points