From 747524c1ca83ba20a61644a37881092047fcad4c Mon Sep 17 00:00:00 2001 From: Fereshteh Yousefirizi <84542058+qurit-frizi@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:15:09 -0700 Subject: [PATCH] Add files via upload --- nifti2rt.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 nifti2rt.py diff --git a/nifti2rt.py b/nifti2rt.py new file mode 100644 index 0000000..17396ec --- /dev/null +++ b/nifti2rt.py @@ -0,0 +1,22 @@ +import SimpleITK as sitk +from SimpleITK import GetArrayFromImage, sitkNearestNeighbor, Image +import numpy as np +from torch import nn +from rt_utils import RTStructBuilder + +def debug_output(seg: sitk.Image, seg_path: str, uid:str, dicom_path: str): + mask_from_sitkImage_zyx = np.transpose(sitk.GetArrayFromImage(seg), (2, 1, 0)) + mask_from_sitkImage_xzy = np.transpose(mask_from_sitkImage_zyx, axes=(2, 0, 1)) + mask_from_sitkImage_xyz = np.transpose(mask_from_sitkImage_xzy, (2, 1, 0)) + mask_from_sitkImage_int64 = mask_from_sitkImage_xyz + mask_from_sitkImage_bool = mask_from_sitkImage_int64.astype(bool) + # Create new RT Struct. Requires the DICOM series path for the RT Struct. + rtstruct = RTStructBuilder.create_new(dicom_series_path = dicom_path) + # Add the 3D mask as an ROI setting the color, description, and name + rtstruct.add_roi( + mask=mask_from_sitkImage_bool, + color=[255, 0, 255], + name="your ROI!" + ) + + rtstruct.save(os.path.join(OUTPUT_DIR, uid+'_tmtv-rt-struct'))