File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -623,14 +623,18 @@ def __init__(
623623 else :
624624 sub_ds = ds
625625
626- if (
627- 'RescaleSlope' in sub_ds or
628- 'RescaleIntercept' in sub_ds
629- ):
626+ # Rescale intercept and slope should not be empty,
627+ # but this has been observed in some data and
628+ # should be handled by assuming slope=1, intercept=0
629+ rescale_slope = sub_ds .get ('RescaleSlope' , None )
630+ rescale_intercept = sub_ds .get ('RescaleIntercept' , None )
631+
632+ if rescale_slope or rescale_intercept :
630633 modality_slope_intercept = (
631- float (sub_ds . get ( 'RescaleSlope' , 1.0 ) ),
632- float (sub_ds . get ( 'RescaleIntercept' , 0.0 ) )
634+ float (rescale_slope or 1.0 ),
635+ float (rescale_intercept or 0.0 )
633636 )
637+
634638 self .applies_to_all_frames = (
635639 self .applies_to_all_frames and is_shared
636640 )
Original file line number Diff line number Diff line change @@ -1017,6 +1017,31 @@ def test_combined_transform_pmap_rwvm_lut():
10171017 tf = _CombinedPixelTransform (pmap , output_dtype = np .float32 )
10181018
10191019
1020+ def test_empty_rescale_slope_intercept_behaves_as_missing ():
1021+ # Construct a CT image with None RescaleSlope/RescaleIntercept
1022+ file_path = Path (__file__ )
1023+ data_dir = file_path .parent .parent .joinpath ('data' )
1024+ f = data_dir / 'test_files/ct_image.dcm'
1025+
1026+ # try all combinations of missing and None: None is treated as missing
1027+ for intercept_none in [False , True ]:
1028+ for slope_none in [False , True ]:
1029+ dataset = pydicom .dcmread (f )
1030+
1031+ del dataset .RescaleIntercept
1032+ del dataset .RescaleSlope
1033+
1034+ if intercept_none :
1035+ dataset .RescaleIntercept = None
1036+
1037+ if slope_none :
1038+ dataset .RescaleSlope = None
1039+
1040+ # parsing succeeds and defaults to no effective slope intercept
1041+ tf = _CombinedPixelTransform (dataset )
1042+ assert tf ._effective_slope_intercept is None
1043+
1044+
10201045def test_get_volume_multiframe_ct ():
10211046 im = imread (get_testdata_file ('eCT_Supplemental.dcm' ))
10221047 volume = im .get_volume ()
You can’t perform that action at this time.
0 commit comments