-
Notifications
You must be signed in to change notification settings - Fork 28
Functions List
- Discover the DICOM
- Setting the index
- Return found ROIs
- Where are certain ROIs?
- Setting wanted ROI names and associations
- Which indexes have all wanted ROIs
- Loading images and masks
- Write images and masks in parallel
- Turn predictions into an RT Structure
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)
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)
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)
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
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)
You can return a list of indexes which have all of the ROIs present using
indexes = Dicom_reader.which_indexes_have_all_rois()
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
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'))
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'])
A special thanks to Kareem Wahid for all his help!