-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrtstruct_loader.py
More file actions
26 lines (21 loc) · 828 Bytes
/
rtstruct_loader.py
File metadata and controls
26 lines (21 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
from rt_utils import RTStructBuilder
def load_rtstruct_masks(rtstruct_path: str, dicom_series_dir: str) -> dict:
"""
Load binary masks from a DICOM RTSTRUCT and its corresponding CT series.
:param rtstruct_path: path to DICOM RTSTRUCT file
:param dicom_series_dir: path to folder containing the CT series
:return: dict of {roi_name: np.ndarray (3D binary mask)}
"""
# Load RTStruct object
rtstruct = RTStructBuilder.create_from(
dicom_series_path=dicom_series_dir,
rt_struct_path=rtstruct_path
)
roi_names = rtstruct.get_roi_names()
print("ROI names:", roi_names)
masks = {}
for name in roi_names:
mask_3d = rtstruct.get_roi_mask_by_name(name) # shape: (z, y, x)
masks[name] = mask_3d.astype(np.uint8)
return masks