Error accessing one ROI name
ttkrpink opened this issue · 1 comments
ttkrpink commented
Code and error message are shown below. Other ROI name is fine so far. Any help? Thanks.
dicom_dir = f"./dicom/Renamed/Pediatric-CT-SEG-028C9198/"
rt_file = f"{dicom_dir}/Mask/1-1.dcm"
rtstruct = RTStructBuilder.create_from(
dicom_series_path=dicom_dir+"Image/",
rt_struct_path=rt_file
)
names = rtstruct.get_roi_names()
print(names)
mask_3d = rtstruct.get_roi_mask_by_name("Breast Left")
first_mask_slice = mask_3d[:, :, 1]
plt.imshow(first_mask_slice) # View one slice within the mask
plt.show()
['Adrenal Left', 'Adrenal Right', 'Bladder', 'Breast Left', 'Breast Right', 'Duodenum', 'Esophagus', 'Femoral Head Lef', 'Femoral Head Rig', 'Gall Bladder', 'Gonads', 'Heart', 'Kidney Left', 'Kidney Right', 'Large Intestine', 'Liver', 'Pancreas', 'Prostate', 'Rectum', 'Small Intestine', 'Spinal Canal', 'Spleen', 'Stomach', 'Thymus', 'UteroCervix', 'Lung_L', 'Lung_R', 'Skin', 'Bones']
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
d:\PythonProjects\AI_Segmention_Pediatric_Organ\step0_clean_names.ipynb Cell 9 in <cell line: 9>()
[7](vscode-notebook-cell:/d%3A/PythonProjects/AI_Segmention_Pediatric_Organ/step0_clean_names.ipynb#X16sZmlsZQ%3D%3D?line=6) names = rtstruct.get_roi_names()
[8](vscode-notebook-cell:/d%3A/PythonProjects/AI_Segmention_Pediatric_Organ/step0_clean_names.ipynb#X16sZmlsZQ%3D%3D?line=7) print(names)
----> [9](vscode-notebook-cell:/d%3A/PythonProjects/AI_Segmention_Pediatric_Organ/step0_clean_names.ipynb#X16sZmlsZQ%3D%3D?line=8) mask_3d = rtstruct.get_roi_mask_by_name("Breast Left")
[10](vscode-notebook-cell:/d%3A/PythonProjects/AI_Segmention_Pediatric_Organ/step0_clean_names.ipynb#X16sZmlsZQ%3D%3D?line=9) first_mask_slice = mask_3d[:, :, 1]
[11](vscode-notebook-cell:/d%3A/PythonProjects/AI_Segmention_Pediatric_Organ/step0_clean_names.ipynb#X16sZmlsZQ%3D%3D?line=10) plt.imshow(first_mask_slice) # View one slice within the mask
File d:\python38\lib\site-packages\rt_utils\rtstruct.py:110, in RTStruct.get_roi_mask_by_name(self, name)
108 for structure_roi in self.ds.StructureSetROISequence:
109 if structure_roi.ROIName == name:
--> 110 contour_sequence = ds_helper.get_contour_sequence_by_roi_number(
111 self.ds, structure_roi.ROINumber
112 )
113 return image_helper.create_series_mask_from_contour_sequence(
114 self.series_data, contour_sequence
115 )
117 raise RTStruct.ROIException(f"ROI of name `{name}` does not exist in RTStruct")
File d:\python38\lib\site-packages\rt_utils\ds_helper.py:221, in get_contour_sequence_by_roi_number(ds, roi_number)
217 for roi_contour in ds.ROIContourSequence:
218
219 # Ensure same type
220 if str(roi_contour.ReferencedROINumber) == str(roi_number):
--> 221 return roi_contour.ContourSequence
223 raise Exception(f"Referenced ROI number '{roi_number}' not found")
File d:\python38\lib\site-packages\pydicom\dataset.py:834, in Dataset.__getattr__(self, name)
832 return {}
833 # Try the base class attribute getter (fix for issue 332)
--> 834 return object.__getattribute__(self, name)
AttributeError: 'Dataset' object has no attribute 'ContourSequence'
asim-shrestha commented
#60 Has a similar issue, is your RT Struct properly constructed?