From f09376c06e5599f273834d0066dc1ae5e42668c1 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 15 Oct 2024 22:32:38 +1100 Subject: [PATCH] Correctly convert colour (RGB) JPEG2000 images --- ev_to_dicom/ev_to_dcm.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ev_to_dicom/ev_to_dcm.py b/ev_to_dicom/ev_to_dcm.py index edb4ef8..368d25c 100644 --- a/ev_to_dicom/ev_to_dcm.py +++ b/ev_to_dicom/ev_to_dcm.py @@ -98,7 +98,12 @@ def ev_files_to_dcm_file(study_uid, series_uid, series_number, image_number, inp ds.Rows = metadata['rows'] if metadata['color']: - ds.PhotometricInterpretation = 'YBR_FULL_422' # Specify YBR as that is how JPEG compression works, even though the JSON says RGB + # FIXME: Any proper way to detect this? + + if file_meta.TransferSyntaxUID == '1.2.840.10008.1.2.4.50': # JPEG + ds.PhotometricInterpretation = 'YBR_FULL_422' # Specify YBR as that is how JPEG compression works, even though the JSON says RGB + else: + ds.PhotometricInterpretation = 'RGB' else: ds.PhotometricInterpretation = 'MONOCHROME2' @@ -110,7 +115,7 @@ def ev_files_to_dcm_file(study_uid, series_uid, series_number, image_number, inp # Store copy of raw metadata block = ds.private_block(0x0075, 'RunasSudo ev-to-dicom', create=True) - block.add_new(0x01, 'UL', 0) # Version + block.add_new(0x01, 'UL', 0) # Data format version del metadata['totalAvailableBytes'] block.add_new(0x02, 'OB', msgpack.packb(metadata))