qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
191 stars 56 forks source link

'FileDataset' object has no attribute 'SliceLocation' #19

Closed sama2689 closed 3 years ago

sama2689 commented 3 years ago

I have an rt-struct.dcm file by itself, I want to extract a 3D volumetric mask from this. From loading the Rt-struct using dicominfo on MATLAB I can see that it has no SliceLocation attribute. However, it does have ROI contour attributes. All I am trying to do is extract these ROI contours (which are currently stored in Cartesian coordinates) as a mask. Is it possible to do this with rt-utils?

awtkns commented 3 years ago

@carluri is this something you want to be supporting? It was written under the assumption that we would always the actual DCM files associated with the RT-STUCTS as there is quite a bit of information you need from the DCM files to generate the RT struct.

If you wanted to change this this should point you in the right direction:

C:\Users\cadam\programming\rt-utils>git grep -n SliceLocation
rt_utils/image_helper.py:25:    series_data.sort(key=lambda ds: ds.SliceLocation, reverse=False)
rt_utils/image_helper.py:138:    z_indicies = np.ones((contour.shape[0], 1)) * series_slice.SliceLocation
clarkbab commented 3 years ago

I'm getting the same error when using RTStructBuilder.create_new(dicom_series_path='/path') with an existing DICOM series. I notice that SliceLocation is an optional attribute, could the same sorting information be obtained from ImagePositionPatient?

SimonBiggs commented 3 years ago

I came here from @pchlap's comment in https://github.com/qurit/rt-utils/pull/21#issue-641906262. I vendored into PyMedPhys some code by @Fincap and @sjswerdloff that achieves this.

The code that does this sorting within PyMedPhys is over at:

https://github.com/pymedphys/pymedphys/blob/9b16b9cbc293276422e7209c658160962405fba9/lib/pymedphys/_dicom/sorting.py#L1-L57

The original code is over at:

https://github.com/didymo/OnkoDICOM/blob/cfab3aefb1427ab251a5de3df1b04d729ecd4b5d/src/Model/ImageLoading.py#L112-L130

And the relicensing discussion occurred over at:

https://github.com/pymedphys/pymedphys/pull/1458#discussion_r598630630

SimonBiggs commented 3 years ago

To add onto this @johndgiese over at innolitics also has a similar solution to this:

https://github.com/innolitics/dicom-numpy/blob/204e95594a527bbab1444f9248432ffa01af024c/dicom_numpy/combine_slices.py#L80-L88

DylanHsu commented 3 years ago

Hi, I'm having the same issue rasterizing structures on some CT series that are missing the optional SliceLocation attribute. It's possible to sanitize our files in the short term, but in the future it would be great to rely on ImagePositionPatient.