From ae015e051e4156fccb5cd38eb3e3cbb43c20a0b5 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 23 Nov 2023 21:33:21 +1100 Subject: [PATCH] Do not append JPEG 2000 end of codestream marker if already present --- ev_to_dicom/ev_to_dcm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ev_to_dicom/ev_to_dcm.py b/ev_to_dicom/ev_to_dcm.py index 1b56867..26fe62e 100644 --- a/ev_to_dicom/ev_to_dcm.py +++ b/ev_to_dicom/ev_to_dcm.py @@ -113,8 +113,8 @@ def ev_files_to_dcm_file(study_uid, series_uid, series_number, image_number, inp block.add_new(0x02, 'OB', msgpack.packb(metadata)) if metadata['imageFormat'] == 0: - # JPEG 2000 - For some reason, the end of codestream tag is missing - ds.PixelData = encapsulate([pixel_data + b'\xff\xd9' for pixel_data in pixel_datas]) + # JPEG 2000 - For some reason, the end of codestream marker is (always?) missing + ds.PixelData = encapsulate([pixel_data if pixel_data.endswith(b'\xff\xd9') else pixel_data + b'\xff\xd9' for pixel_data in pixel_datas]) else: ds.PixelData = encapsulate(pixel_datas)