Skip to content

Commit

Permalink
enable passing of the ROI type you are writing
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmanderson committed Nov 17, 2023
1 parent ec556a3 commit ece340a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/DicomRTTool/ReaderWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def write_images_annotations(self, out_path: typing.Union[str, bytes, os.PathLik
fid.close()

def prediction_array_to_RT(self, prediction_array: np.array, output_dir: typing.Union[str, bytes, os.PathLike],
ROI_Names: List[str]) -> None:
ROI_Names: List[str], ROI_Types: List[str] = None) -> None:
"""
:param prediction_array: numpy array of prediction, expected shape is [#Images, Rows, Cols, #Classes + 1]
:param output_dir: directory to pass RT structure to
Expand Down Expand Up @@ -1388,6 +1388,10 @@ def prediction_array_to_RT(self, prediction_array: np.array, output_dir: typing.
print('RT Structure not made for ROIs {}, given prediction_array had no mask'.format(not_contained))
self.image_size_z, self.image_size_rows, self.image_size_cols = prediction_array.shape[:3]
self.ROI_Names = ROI_Names
if ROI_Types is None:
self.ROI_Types = ["ORGAN" for _ in ROI_Names]
else:
self.ROI_Types = ROI_Types
self.output_dir = output_dir
if len(prediction_array.shape) == 3:
prediction_array = np.expand_dims(prediction_array, axis=-1)
Expand Down Expand Up @@ -1422,7 +1426,7 @@ def mask_to_contours(self) -> None:
[255, 255, 255]]
self.struct_index = 0
new_ROINumber = 1000
for Name in self.ROI_Names:
for Name, ROI_Type in zip(self.ROI_Names, self.ROI_Types):
new_ROINumber -= 1
if not temp_color_list:
temp_color_list = copy.deepcopy(color_list)
Expand Down Expand Up @@ -1454,13 +1458,8 @@ def mask_to_contours(self) -> None:
self.RS_struct.RTROIObservationsSequence[self.struct_index].ObservationNumber = new_ROINumber
self.RS_struct.RTROIObservationsSequence[self.struct_index].ReferencedROINumber = new_ROINumber
self.RS_struct.RTROIObservationsSequence[self.struct_index].ROIObservationLabel = Name

if 'ctv' in Name.lower():
self.RS_struct.RTROIObservationsSequence[self.struct_index].RTROIInterpretedType = 'CTV'
elif 'ptv' in Name.lower():
self.RS_struct.RTROIObservationsSequence[self.struct_index].RTROIInterpretedType = 'PTV'
else:
self.RS_struct.RTROIObservationsSequence[self.struct_index].RTROIInterpretedType = 'ORGAN'

self.RS_struct.RTROIObservationsSequence[self.struct_index].RTROIInterpretedType = ROI_Type

if make_new == 1:
self.RS_struct.ROIContourSequence.insert(0, copy.deepcopy(self.RS_struct.ROIContourSequence[0]))
Expand Down

0 comments on commit ece340a

Please sign in to comment.