Skip to content

Commit

Permalink
Add padding to ensure even LUT
Browse files Browse the repository at this point in the history
  • Loading branch information
CPBridge committed Apr 12, 2024
1 parent 081533f commit 5d77c95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/highdicom/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,12 @@ def __init__(
)
self._attr_name_prefix = f'{color.title()}PaletteColorLookupTable'

if bits_per_entry == 8 and len(lut_data) % 2 != 0:
# Need to pad so that the resulting value has even length
lut_data = np.concatenate(
[lut_data, np.array([0], lut_data.dtype)]
)

# The Palette Color Lookup Table Data attributes have VR OW
# (16-bit other words)
setattr(
Expand Down
4 changes: 2 additions & 2 deletions src/highdicom/seg/sop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,11 +1729,11 @@ def __init__(
lut_end = lut_start + lut_entries

if (
(lut_start > 1) or lut_end <= len(segment_descriptions)
(lut_start > 0) or lut_end <= len(segment_descriptions)
):
raise ValueError(
'The labelmap provided does not have entries '
'to cover all segments.'
'to cover all segments and background.'
)

for desc in segment_descriptions:
Expand Down

0 comments on commit 5d77c95

Please sign in to comment.