Skip to content

Commit 63bc1e5

Browse files
Deduplicate DICOM fallback colors
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
1 parent 99fd12b commit 63bc1e5

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

monailabel/datastore/utils/colors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@
332332
# Distinct, non-background colors used to give segments without a known anatomy
333333
# name (and without an explicit color) different colors instead of all defaulting
334334
# to red. See issue #1751.
335-
_FALLBACK_COLORS = [color for name, color in GENERIC_ANATOMY_COLORS.items() if name != _BACKGROUND_KEY]
335+
_FALLBACK_COLORS = list(
336+
dict.fromkeys(color for name, color in GENERIC_ANATOMY_COLORS.items() if name != _BACKGROUND_KEY)
337+
)
336338

337339

338340
def get_segment_color(name, info=None, index=0):

tests/unit/datastore/test_colors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
from monailabel.datastore.utils.colors import GENERIC_ANATOMY_COLORS, get_segment_color
1515

16-
# Number of unnamed segments used to check that fallback colors are distinct.
17-
_UNNAMED_SEGMENTS = 5
16+
# Number of unnamed segments needed to cover the fallback palette's first
17+
# duplicate RGB value, which previously appeared at indices 4 and 16.
18+
_UNNAMED_SEGMENTS = 17
1819
# The color every unnamed segment used to collapse to before the fix (issue #1751).
1920
_LEGACY_RED = [255, 0, 0]
2021
# Black background color that must never be assigned to a segment.

0 commit comments

Comments
 (0)