From bb4dad72aa4b1e2ddf9bf521b1bcb5b2f21c01d9 Mon Sep 17 00:00:00 2001 From: Umar Yousafzai <39500143+uyousafzai54@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:00:36 -0400 Subject: [PATCH 1/3] add stop_before_pixels tag and set to True to speed up dcm reads (#80) AYE AYE --- imgtools/utils/crawl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgtools/utils/crawl.py b/imgtools/utils/crawl.py index 732691d..666fb4d 100644 --- a/imgtools/utils/crawl.py +++ b/imgtools/utils/crawl.py @@ -25,7 +25,7 @@ def crawl_one(folder): rel_path = dcm_path.relative_to(folder_path.parent.parent) # rel_path of dicom from folder rel_posix = rel_path.parent.as_posix() # folder name + until parent folder of dicom - meta = dcmread(dcm, force=True) + meta = dcmread(dcm, force=True, stop_before_pixels=True) patient = str(meta.PatientID) study = str(meta.StudyInstanceUID) series = str(meta.SeriesInstanceUID) From 1268cbc668d2960e3dbb66955ed84b298bb1a651 Mon Sep 17 00:00:00 2001 From: Sejin Kim <40668167+skim2257@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:03:48 -0400 Subject: [PATCH 2/3] test break during demo (#81) * test break during demo - changed https://github.com/bhklab/med-imagetools/blob/d99950f4240ec286deeef6d635fe329ca520f2a7/imgtools/modules/datagraph.py#L61 set 2nd half pandas`astype(str)` * Update setup.py to 1.1.6 --- imgtools/modules/datagraph.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgtools/modules/datagraph.py b/imgtools/modules/datagraph.py index 81821fd..5caf0db 100644 --- a/imgtools/modules/datagraph.py +++ b/imgtools/modules/datagraph.py @@ -58,7 +58,7 @@ def form_graph(self): 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"]], + 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") diff --git a/setup.py b/setup.py index 18b13ef..aaf1cfc 100644 --- a/setup.py +++ b/setup.py @@ -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.", From ba50037fee4c0c6bc0640d5efdc074ea75944da7 Mon Sep 17 00:00:00 2001 From: RuiyanNi <91274748+RuiyanNi@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:02:03 -0400 Subject: [PATCH 3/3] convert to dicom (#89) nifti to dicom function --- imgtools/utils/nifti_to_dicom.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 imgtools/utils/nifti_to_dicom.py diff --git a/imgtools/utils/nifti_to_dicom.py b/imgtools/utils/nifti_to_dicom.py new file mode 100644 index 0000000..0cf9d2b --- /dev/null +++ b/imgtools/utils/nifti_to_dicom.py @@ -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)