Python 属性错误:';文件数据集';对象没有属性';切片位置';
我使用下面的代码,我从一些文章Python 属性错误:';文件数据集';对象没有属性';切片位置';,python,pydicom,Python,Pydicom,我使用下面的代码,我从一些文章 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 ##
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
函数名称:getattr
消息:返回超级(数据集,自我)。getattribute(名称)
正如你在这里看到的:
“切片位置”属性是可选的。抛出的错误意味着不存在这样的属性。因此,根据DICOM标准,可以预期会收到此错误