AttributeError: 'FileDataset' object has no attribute 'Modality'

82 views Asked by At

I am a novice to ML and trying to apply TotalSegmentator to my .dcm files. Initially, I was trying to convert my dcm files to nifti using dicom2nifti but I got this error

AttributeError: 'FileDataset' object has no attribute 'Modality'

now I'm using totalsegmentator to and am getting the same.

totalsegmentator('/PATH_TO_DIR/train_images/10004/21057','/outs')

I tired looking into the dcm file using pydicoms dcmread but could not find modality in it. But my dataset does suggest standardizing the dcms like this:

def standardize_pixel_array(dcm: pydicom.dataset.FileDataset) -> np.ndarray:
    # Correct DICOM pixel_array if PixelRepresentation == 1.
    pixel_array = dcm.pixel_array
    if dcm.PixelRepresentation == 1:
        bit_shift = dcm.BitsAllocated - dcm.BitsStored
        dtype = pixel_array.dtype 
        pixel_array = (pixel_array << bit_shift).astype(dtype) >>  bit_shift
        pixel_array = pydicom.pixel_data_handlers.util.apply_modality_lut(pixel_array, dcm)
    return pixel_array
0

There are 0 answers