AttributeError: 'FileDataset' 对象没有属性

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


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' 对象没有属性 'SliceLocation'



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


线路 : 524,


Func.Name : getattr ,


消息:返回超级(数据集,自我)。获取属性(名称)


慕码人2483693
浏览 441回答 1
1回答

长风秋雁

正如您在此处看到的: DICOM 标准Slice Location 属性是可选的。抛出的错误意味着没有这样的属性。所以就 DICOM 标准而言,收到此错误是可以预料的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python