Radhi
Radhi

Reputation: 6339

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

I am using below code I got from some articles.

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

Got below error

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

at

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

Line : 524,

Func.Name : getattr,

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

Upvotes: 1

Views: 2810

Answers (1)

g_uint
g_uint

Reputation: 2041

As you can see here: DICOM Standard
The Slice Location attribute is optional. The error that is thrown means that there is no such attribute. So in terms of the DICOM standard, receiving this error can be expected.

Upvotes: 2

Related Questions