-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shorthand function to merge two pre-existing RTStruct structure s…
…ets (#70) ✨ Add class to merge two pre-existing RTStruct structure sets
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .rtstruct import RTStruct | ||
from .rtstruct_builder import RTStructBuilder | ||
from .rtstruct_merger import RTStructMerger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from .rtstruct import RTStruct | ||
from .rtstruct_builder import RTStructBuilder | ||
from . import ds_helper, image_helper | ||
|
||
class RTStructMerger: | ||
|
||
|
||
@staticmethod | ||
def merge_rtstructs(dicom_series_path: str, rt_struct_path1: str, | ||
rt_struct_path2: str) -> RTStruct: | ||
""" | ||
Method to merge two existing RTStruct files belonging to same series data, returning them as one RTStruct | ||
""" | ||
|
||
rtstruct1 = RTStructBuilder.create_from(dicom_series_path, rt_struct_path1) | ||
rtstruct2 = RTStructBuilder.create_from(dicom_series_path, rt_struct_path2) | ||
|
||
for roi_contour_seq, struct_set_roi_seq, rt_roi_observation_seq in zip(rtstruct1.ds.ROIContourSequence, rtstruct1.ds.StructureSetROISequence, rtstruct1.ds.RTROIObservationsSequence): | ||
roi_number = len(rtstruct2.ds.StructureSetROISequence) + 1 | ||
roi_contour_seq.ReferencedROINumber = roi_number | ||
struct_set_roi_seq.ROINumber = roi_number | ||
rt_roi_observation_seq.ReferencedROINumber = roi_number | ||
|
||
# check for ROI name duplication | ||
for struct_set_roi_seq2 in rtstruct2.ds.StructureSetROISequence: | ||
if struct_set_roi_seq.ROIName == struct_set_roi_seq2.ROIName: | ||
struct_set_roi_seq += "_2" | ||
|
||
rtstruct2.ds.ROIContourSequence.append(roi_contour_seq) | ||
rtstruct2.ds.StructureSetROISequence.append(struct_set_roi_seq) | ||
rtstruct2.ds.RTROIObservationsSequence.append(rt_roi_observation_seq) | ||
|
||
return rtstruct2 |