Correctly convert colour (RGB) JPEG2000 images

This commit is contained in:
RunasSudo 2024-10-15 22:32:38 +11:00
parent 2f76ace0b7
commit f09376c06e
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -98,7 +98,12 @@ def ev_files_to_dcm_file(study_uid, series_uid, series_number, image_number, inp
ds.Rows = metadata['rows'] ds.Rows = metadata['rows']
if metadata['color']: if metadata['color']:
# 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 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: else:
ds.PhotometricInterpretation = 'MONOCHROME2' 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 # Store copy of raw metadata
block = ds.private_block(0x0075, 'RunasSudo ev-to-dicom', create=True) 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'] del metadata['totalAvailableBytes']
block.add_new(0x02, 'OB', msgpack.packb(metadata)) block.add_new(0x02, 'OB', msgpack.packb(metadata))