brianmanderson / Dicom_RT_and_Images_to_Mask

Tools to help with the conversion of DICOM images, RT Structures, and dose to useful Python objects. Essentially DICOM to NumPy and SimpleITK Images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with some RTStruct data for converting to NumPy Masks

naveensweth opened this issue · comments

Dear Brianmanderson,
Thank you very for your work.

I am using your script for converting RTStruct data into Numpy Masks but some datasets its giving error "Dataset' object has no attribute 'ContourSequence".

Note: Its working fine with the "Example data" which I downloaded from your repo link.

Kindly let me know what I am missing here and please guide me to solve these issues.

Issue 1:
Dataset' object has no attribute 'ContourSequence' with below ROIs
("brai" , "spinal canal")

Issue 2: Below issue with different RTStruct data.

Dicom_reader.get_images_and_mask()
File "C:\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py", line 964, in get_images_and_mask
self.get_mask()
File "C:\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py", line 1113, in get_mask
mask = self.contours_to_mask(structure_index)
File "C:\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py", line 1206, in contours_to_mask
matrix_points = self.reshape_contour_data(Contour_data[i].ContourData[:])
File "C:\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py", line 1141, in reshape_contour_data
matrix_points = np.asarray([self.dicom_handle.TransformPhysicalPointToIndex(as_array[i])
File "C:\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py", line 1141, in
matrix_points = np.asarray([self.dicom_handle.TransformPhysicalPointToIndex(as_array[i])
File "C:\Python\Python38\lib\site-packages\SimpleITK\SimpleITK.py", line 3242, in TransformPhysicalPointToIndex
return _SimpleITK.Image_TransformPhysicalPointToIndex(self, point)
TypeError: in method 'Image_TransformPhysicalPointToIndex', argument 2 of type 'std::vector< double,std::allocator< double > > const &'

Thank you

Hi Naveen,

That error should only be popping up when the RT structure file does not have the attribute ContourSequence. Essentially this means that there are no ROI points for that structure present.

We've had some issues in the past with people working with structures that are not DicomRT (Like this issue #22 ) but otherwise I'm not sure what could be happening

For issue 2, that looks like there's an issue occurring in transforming the physical point to an index..which is very odd. Could you please send me the example of your code snippet?

Brian

Hi Naveen,

That error should only be popping up when the RT structure file does not have the attribute ContourSequence. Essentially this means that there are no ROI points for that structure present.

We've had some issues in the past with people working with structures that are not DicomRT (Like this issue #22 ) but otherwise I'm not sure what could be happening

For issue 2, that looks like there's an issue occurring in transforming the physical point to an index..which is very odd. Could you please send me the example of your code snippet?

Brian

Thank you very much for the prompt reply

Issue 2:

Code snippet:

file mangagment

import os

array manipulation

import numpy as np
import SimpleITK as sitk

from DicomRTTool.ReaderWriter import DicomReaderWriter

Dicom_path = r'C:\RTStruct\rtstructData\data'
Dicom_reader = DicomReaderWriter(description='Examples', arg_max=True)
Dicom_reader.walk_through_folders(Dicom_path)
all_rois = Dicom_reader.return_rois(print_rois=True)

Dicom_reader.set_contour_names_and_associations(Contour_Names=all_rois)

Dicom_reader.get_images_and_mask()

image = Dicom_reader.ArrayDicom # image array
mask = Dicom_reader.mask # mask array
dicom_sitk_handle = Dicom_reader.dicom_handle # SimpleITK image handle
mask_sitk_handle = Dicom_reader.annotation_handle # SimpleITK mask handle

nifti_path = os.path.join('.', 'Example_Data', 'Nifti_Data') # nifti subfolder
if not os.path.exists(nifti_path):
os.makedirs(nifti_path)

dicom_sitk_handle = Dicom_reader.dicom_handle # SimpleITK image handle
mask_sitk_handle = Dicom_reader.annotation_handle # SimpleITK mask handle
sitk.WriteImage(dicom_sitk_handle, os.path.join(nifti_path, 'Image.nii'))
sitk.WriteImage(mask_sitk_handle, os.path.join(nifti_path, 'Mask.nii'))


Hi Brian,

Issue 1:
The RTStruct file has 12 ROIs and I confirmed with this "all_rois = Dicom_reader.return_rois(print_rois=True" which returns all rois points and same as assigned to Dicom_reader.set_contour_names_and_associations(Contour_Names=all_rois) but its throwing error for only 2 rois ['brai' , 'spinal canal'] and others 10 rois are working fine with the same RTstruct dataset.

Issue2:
I am just running with different rtstruct data with your script and didn't make any change in the ReadWriter.py file.
DicomRTTool-1.0.0\Dicom_RT_and_Images_to_Mask\src\DicomRTTool\ReaderWriter.py

Issue 1: Based on where the error is being thrown it looks like those rois are empty, I'm adding a line now to try and remedy that issue. The ROI could exist in the structure, but be empty otherwise

Issue 2: Are the ROIs being defined outside of the image physical space? This could be an issue with the program trying to create a negative index

Is there any chance you could anonymize the data and upload to google drive? I could look at it there

Just made a commit to the main branch which should solve issue 1 e732eee

Dear Brian,
Thanks for the information.

Issue 1:

Thanks for the update. I checked it and there is no above error but the "Dicom_reader.return_rois()" returns a total of 12 rois but it shows only one roi ('Body') display in the slicer tool.

Dicom_reader.set_contour_names_and_associations(Contour_Names=all_rois)

I noticed that if I skip the 'body' roi then generate label map with your script and loaded into slicer it shows 11 rois.

Dicom_reader.set_contour_names_and_associations(Contour_Names=all_rois[1:]) (skipping first 'body' roi and passing to this api)
Kindly let me know if I need to make any changes from my end.


Issue 2:
Sorry I cannot share the data due to security reasons.
Note: I have loaded the same dataset into slicer tool and it generated label maps without any issues

Thank you very much.

Hi Naveen,

Unfortunately I'm not really sure what might be happening =/, it is difficult to identify any issue without being able to evaluate data. Shoot me an email at markba122@gmail.com and maybe we can set up a time to do a Zoom call and review the data without you having to share it

Cheers,
Brian