From 5d77c955c941be160984fb998ed305136170b13e Mon Sep 17 00:00:00 2001 From: Chris Bridge Date: Thu, 1 Feb 2024 16:02:03 +0000 Subject: [PATCH] Add padding to ensure even LUT --- src/highdicom/content.py | 6 ++++++ src/highdicom/seg/sop.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/highdicom/content.py b/src/highdicom/content.py index 026e36b0..aa758e03 100644 --- a/src/highdicom/content.py +++ b/src/highdicom/content.py @@ -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( diff --git a/src/highdicom/seg/sop.py b/src/highdicom/seg/sop.py index 6d74d923..847ec7c6 100644 --- a/src/highdicom/seg/sop.py +++ b/src/highdicom/seg/sop.py @@ -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: