Skip to content

Commit

Permalink
conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
skim2257 committed Dec 11, 2023
2 parents dca2c42 + ba50037 commit 31f6ee9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions imgtools/modules/datagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def form_graph(self):
for col in self.df:
self.df[col] = self.df[col].astype(str)

# Get reference_rs information from RTDOSE-RTPLAN connections
df_filter = pd.merge(self.df, self.df[["instance_uid","reference_rs"]],
#Get reference_rs information from RTDOSE-RTPLAN connections
df_filter = pd.merge(self.df, self.df[["instance_uid","reference_rs"]].apply(lambda x: x.astype(str), axis=1),
left_on="reference_pl",
right_on="instance_uid",
how="left")
Expand Down
46 changes: 46 additions & 0 deletions imgtools/utils/nifti_to_dicom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import SimpleITK as sitk
from rt_utils import RTStructBuilder
import pydicom
import logging
import glob
import numpy as np
import os

'''You need to install rt_utils first using
pip install rt_utils'''


def segmentations_to_dicom(save_path:str,orig_series_info:dict, segmentation:sitk.Image,segmentations_labels:dict,
color_list=None, rtstruct_basefilename='rtstruct.dcm'):
"""
This function takes a list of the original dicom data, moves it to the save_path and creates a corresponding rt_struct
@param image_set_name: name of the image set used to create the dicom sub directory
@param save_path: directory to save dicom data
@param orig_series_info: original series info see @get_dicom_series_dict_pyd
@param segmentation: the image containing integer segmentation data
@param segmentations_labels: a dictionary with segmentation label information mapping ints in @segmentation to label
name e.g. {1: 'Bladder', 2: 'Rectum', 3: 'Sigmoid', 4: 'SmallBowel'}
@return:
"""
_logger=logging.getLogger(__name__)
#make output dir
if not os.path.isdir(save_path):
_logger.warning(f'Making path: {save_path}')
os.makedirs(save_path)


im_array = sitk.GetArrayFromImage(segmentation)
rtstruct = RTStructBuilder.create_new(dicom_series_path=orig_series_info)
for i,(key,name) in enumerate(segmentations_labels.items()):
mask = np.where(im_array!=key,0,im_array)
mask = np.array(mask,dtype=bool)
mask = np.transpose(mask, (1,2,0))

index = i%len(color_list)

rtstruct.add_roi(mask=mask, name=name, color=color_list[index],approximate_contours=False)


rtstruct_name = os.path.join(save_path,rtstruct_basefilename)
_logger.info(f'Saving rtstruct data: {rtstruct_name}')
rtstruct.save(rtstruct_name)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="med-imagetools",
version="1.1.5",
version="1.1.6",
author="Sejin Kim, Michal Kazmierski, Kevin Qu, Vishwesh Ramanathan, Benjamin Haibe-Kains",
author_email="benjamin.haibe.kains@utoronto.ca",
description="Transparent and reproducible image processing pipelines in Python.",
Expand Down

0 comments on commit 31f6ee9

Please sign in to comment.