Assign distinct colors to DICOM SEG segments (ITK export path) - #1909
Assign distinct colors to DICOM SEG segments (ITK export path)#1909ousamabenyounes wants to merge 2 commits into
Conversation
The ITK/dcmqi DICOM SEG export path built each segment's color as
info.get("color", GENERIC_ANATOMY_COLORS.get(name, (255, 0, 0))). When a
segment had no explicit color and its name was not a known anatomy term,
every segment fell back to red, so a multi-segment DICOM SEG showed up
entirely red.
Add a get_segment_color() helper that keeps the existing priority
(explicit color > known anatomy name) but, for the remaining case, picks a
distinct color from the generic-anatomy palette by segment index instead of
always red. The black background entry is excluded so a segment is never
invisible.
Fixes Project-MONAI#1751
Signed-off-by: Ben Younes <benyounes.ousama@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. WalkthroughThe change adds centralized segment color resolution. Explicit metadata colors take precedence, known anatomy names use the anatomy palette, and unknown segments receive indexed non-background colors. ITK/dcmqi conversion now uses this helper. ChangesSegment Color Resolution
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to This PR localizes the color-selection change to the ITK DICOM SEG export path and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@monailabel/datastore/utils/colors.py`:
- Around line 332-335: Update the _FALLBACK_COLORS construction in colors.py to
remove duplicate RGB tuples while preserving their original order, so
modulo-based indexing cannot reuse colors from duplicate entries. Extend the
regression test covering fallback color selection to include the first duplicate
span, including at least 17 unknown segments.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 04c02e51-910a-43f1-986d-ff8807a57872
📒 Files selected for processing (3)
monailabel/datastore/utils/colors.pymonailabel/datastore/utils/convert.pytests/unit/datastore/test_colors.py
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
|
Thanks for the review. Addressed the duplicate fallback RGB values in Validation: the expanded test reproduced RED ( |
|
Clarification on validation: all repository pre-commit hooks pass locally from a clean isolated cache on Python 3.12. The remote pre-commit.ci status is failing because the pinned |
Summary
Fixes #1751 — DICOM SEG shows all segments as the same color (red).
The ITK/dcmqi export path used the same red fallback whenever a segment had no explicit color and its name was absent from
GENERIC_ANATOMY_COLORS.Change
get_segment_color(name, info, index)with the existing priority: explicit color, known anatomy color, then an indexed fallback palette color._itk_nifti_to_dicom_segand cover the first prior duplicate span with 17 unknown segments.Behavior for explicit colors and known anatomy names is unchanged. The default highdicom path is unaffected.
Test verification (RED → GREEN)
RED — before palette deduplication, the 17-segment regression failed:
GREEN — after deduplication:
All repository pre-commit hooks pass locally from a clean isolated cache on Python 3.12. The remote pre-commit.ci run is currently blocked by the pinned
pyupgradehook crashing inside pre-commit.ci's Python 3.14 environment (TypeError: cannot use a bytes pattern on a string-like object); black, flake8, mypy, and every other remote hook pass.The full local unit replay is iso-baseline: upstream and this branch both stop during collection on the same pre-existing
girder_client/pkg_resourcesdependency incompatibility; this branch collects five additional tests before that identical failure.