1

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)

Community
  • 1
  • 1
Radhi
  • 6,289
  • 15
  • 47
  • 68

1 Answers1

2

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.

g_uint
  • 1,903
  • 3
  • 17
  • 30
  • So How to generate coronal and saggital view? – Pygirl Aug 12 '21 at 15:15
  • https://pydicom.github.io/pydicom/stable/auto_examples/image_processing/reslice.html – g_uint Aug 12 '21 at 15:45
  • I mean if there is no sliceLocation attribute. Will it be okay to sort the dcm by number sequence and then do it? – Pygirl Aug 12 '21 at 17:57
  • I presume you mean instance number, and for clinical purposes that is NOT a good measure for ordering your slices unfortunately. Well explained, and how to do it here: https://stackoverflow.com/a/6598664/2878353 – g_uint Aug 13 '21 at 07:46