Skip to content

Commit

Permalink
added conditions for non RGB dicoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Apr 25, 2024
1 parent bdcf508 commit f9ac71d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions dicom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
_ _ _ __ _ _ _
Expand All @@ -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 = '',
Expand Down Expand Up @@ -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))





Expand Down

0 comments on commit f9ac71d

Please sign in to comment.