Skip to content

Functions List

Brian Mark Anderson edited this page Jan 12, 2021 · 2 revisions

Functions list

Below is a list of functions provided by the DicomReaderWriter after creation

  1. Discover the DICOM
  2. Setting the index
  3. Return found ROIs
  4. Where are certain ROIs?
  5. Setting wanted ROI names and associations
  6. Which indexes have all wanted ROIs
  7. Loading images and masks
  8. Write images and masks in parallel
  9. Turn predictions into an RT Structure

Discovering DICOM images and RT-Structures

This instructs the model to walk through all files, nested folders, and subfolders at a particular location. This step is what builds the series_instances_dictionary and should be your first step

     Dicom_reader.walk_through_folders(Dicom_Path)

Setting the index

If there are more than one series instance UID present, the module will print out a list of index values and associated paths. The default index is 0, if you wish to change it use

     Dicom_reader.set_index(index)

Discovering ROIs present

After walking through folders, you can query what ROIs are present. Note that all ROI names are placed into lower-case

     Dicom_reader.return_rois(print_rois=True)

Where is a specific ROI?

You can find a list of all RT-Structures which have a specific ROI name using

     Dicom_reader.where_is_ROI(ROIName='BrAiNsTeM1')  # All ROI names are automatically lower-cased

Set desired Contour names and associations

Once you know what ROIs you want and their associations, you can set them using the following

     Contour_names = ['Disease', 'Liver']
     associations = {'Liver_BMA_Program_4': 'Liver'}  # {'Variant name': 'Target name'}
     Dicom_reader.set_contour_names_and_associations(Contour_Names=Contour_Names, associations=associations)

Which indexes have all the ROIs I want?

You can return a list of indexes which have all of the ROIs present using

     indexes = Dicom_reader.which_indexes_have_all_rois()

I want images, and/or a mask

If you want images or a mask of the desired structures, you can run the commands below

     Dicom_reader.get_images()  # Just load the images
     Dicom_reader.get_mask()  # Load the mask (will load images if you haven't already)
     Dicom_reader.get_images_and_mask()  # wrapper for them both

I want to write out images and masks for all of the cases that have what I want

There is a parallel function for writing out images, masks, and dose files in the format of "OverallData{description}_ {iteration}.nii.gz" (image) or "Overallmask{description}_ y{iteration}.nii.gz" (mask) Note also that an excel sheet will be created that ties the SeriesInstanceUIDs with iterations

     nifti_path = some_path
     Dicom_reader.write_parallel(out_path=nifti_path , excel_file = os.path.join(nifti_path,'.','MRN_Path_To_Iteration.xlsx'))

I want to create an RT structure

In order to create an RT structure you first need to load the images of the scan you want to write out. Please see .get_images() You'll need to pass a NumPy prediction array of the same size of the image array (Dicom_reader.ArrayDicom) plus # channels + 1

     image = Dicom_reader.ArrayDicom
     image_shape = image.shape
     number_of_classes = 1  # Just say we have a square

     predictions = np.zeros(image_shape  + (number_of_classes + 1,))  # Class and background
     predictions[image_shape[0]//2 , image_shape[1]//4:image_shape[1]//2, image_shape[2]//4:image_shape[2]//2, 1] = 1  # Here we are drawing a square

     Dicom_reader.prediction_array_to_RT(prediction_array=predictions, output_dir=RT_path, ROI_Names=['New_Square'])