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

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

我正在使用从一些文章中获得的以下代码。

def load_patient(files):       
    slices = [pydicom.dcmread(s) for s in files]
    slices.sort(key = lambda x: int(x.InstanceNumber))

    try:
        ## actual property is ImagePositionPatient, shortened for screen width ##
        thickness = np.abs(slices[0].ImgPosPatient[2] - slices[1].ImgPosPatient[2])
    except:
        thickness = np.abs(slices[0].SliceLocation - slices[1].SliceLocation)

    for s in slices:
        s.SliceThickness = thickness

    return slices

低于错误

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

File : C:\ProgramData\Anaconda3\lib\site-packages\pydicom\dataset.py

Line : 524,

Func.Name : getattr,

Message : return super(Dataset, self).getattribute(name)

如您所见: DICOM Standard
切片位置属性是可选的。抛出的错误意味着没有这样的属性。所以按照DICOM标准,收到这个错误是可以预料的。