qurit / qurit/rt-utils

Error accessing one ROI name

Open
#61 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
256
Forks
75
PR merge metrics
No merged PRs in 30d

Description

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'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied example with the referenced DICOM series, then inspect rt_utils/rtstruct.py and rt_utils/ds_helper.py around get_roi_mask_by_name and get_contour_sequence_by_roi_number. Determine why the reported ROI reaches a Dataset without ContourSequence and add or document handling that matches the library's expected RTSTRUCT data; verify the reported ROI can be processed without the shown AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.