From f9ac71ddedd057c9d8eeb4d42b6cabed0ff1a1c3 Mon Sep 17 00:00:00 2001 From: "sandipsamal117@gmail.com" Date: Thu, 25 Apr 2024 15:33:38 -0400 Subject: [PATCH] added conditions for non RGB dicoms --- dicom_filter.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dicom_filter.py b/dicom_filter.py index c93c236..6e13d5a 100755 --- a/dicom_filter.py +++ b/dicom_filter.py @@ -10,7 +10,7 @@ from pflog import pflog from pydicom.pixel_data_handlers import convert_color_space import numpy as np -__version__ = '1.1.8' +__version__ = '1.2.0' DISPLAY_TITLE = r""" _ _ _ __ _ _ _ @@ -34,7 +34,7 @@ parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {__version__}') parser.add_argument('-t', '--outputType', default='dcm', type=str, - help='input file filter glob') + help='output file type(extension only)') parser.add_argument( '--pftelDB', dest = 'pftelDB', default = '', @@ -102,10 +102,16 @@ def save_as_image(dcm_file, output_file_path, file_ext): pixel_array_numpy = dcm_file.pixel_array output_file_path = str(output_file_path).replace('dcm', file_ext) print(f"Saving output file as {output_file_path}") + print(f"Photometric Interpretation is {dcm_file.PhotometricInterpretation}") # Prevents color inversion happening while saving as images - rgb = convert_color_space(pixel_array_numpy, "YBR_FULL", "RGB") - cv2.imwrite(output_file_path,cv2.cvtColor(rgb,cv2.COLOR_RGB2BGR)) + if 'YBR' in dcm_file.PhotometricInterpretation: + print(f"Explicitly converting color space to RGB") + pixel_array_numpy = convert_color_space(pixel_array_numpy, "YBR_FULL", "RGB") + + cv2.imwrite(output_file_path,cv2.cvtColor(pixel_array_numpy,cv2.COLOR_RGB2BGR)) + +