platipy.dicom.io package#
Submodules#
platipy.dicom.io.crawl module#
- platipy.dicom.io.crawl.fix_missing_data(contour_data_list)#
Fixes missing points in contouring using simple linear interpolation
- Parameters:
contour_data_list (list) – The contour data for each slice
- Returns:
Interpolated contour data
- Return type:
contour_data (numpy array)
- platipy.dicom.io.crawl.flatten(itr)#
- platipy.dicom.io.crawl.get_dicom_info_from_description(dicom_object, return_extra=False, sop_class_name='UNKNOWN')#
Attempts to return some information from a DICOM This is typically used for naming converted NIFTI files
- Parameters:
dicom_object (pydicom.dataset.FileDataset) – The DICOM object
return_extra (bool, optional) – return information that is usually not required
- Returns:
Some extracted information
- Return type:
info (str)
- platipy.dicom.io.crawl.get_suv_bw_scale_factor(ds)#
- platipy.dicom.io.crawl.process_dicom_directory(dicom_directory, parent_sorting_field='PatientName', output_image_name_format='{parent_sorting_data}_{study_uid_index}_{Modality}_{image_desc}_{SeriesNumber}', output_structure_name_format='{parent_sorting_data}_{study_uid_index}_{Modality}_{structure_name}', output_dose_name_format='{parent_sorting_data}_{study_uid_index}_{DoseSummationType}', return_extra=True, output_directory='./', output_file_suffix='.nii.gz', overwrite_existing_files=False, write_to_disk=True, verbose=False, initial_sop_class_name_default='UNKNOWN')#
- platipy.dicom.io.crawl.process_dicom_file_list(dicom_file_list, parent_sorting_field='PatientName', verbose=False)#
Organise the DICOM files by the series UID
- platipy.dicom.io.crawl.process_dicom_series(dicom_series_dict, series_uid, parent_sorting_field='PatientName', return_extra=True, individual_file=False, initial_sop_class_name_default='UNKNOWN')#
- platipy.dicom.io.crawl.safe_sort_dicom_image_list(dicom_image_list)#
Sorts a list of DICOM image files based on a DICOM tag value. This is a much safer method than reading SliceLocation. It takes mandatory DICOM fields (Image Position [Patient]) and (Image Orientation [Patient]). The list of DICOM files is sorted by projecting the image position onto the axis normal to the place defined by the image orientation.
This accounts for differences in patient position (e.g. HFS/FFS).
- Parameters:
dicom_image_list (list) – [description]
- platipy.dicom.io.crawl.transform_point_set_from_dicom_struct(image, dicom_struct, spacing_override=False)#
This function is used to generate a binary mask from a set of vertices. This allows us to convert from DICOM-RTStruct format to any imaging format.
- Parameters:
image ([SimpleITK.Image]) – The image, used to copy imaging information (e.g. resolution, spacing)
dicom_struct ([pydicom.Dataset]) – The DICOM-RTStruct file
spacing_override (bool | tuple, optional) – Overwrite the spacing. Set with (axial_spacing, coronal_spacing, sagittal spacing). Defaults to False.
- Returns:
final_struct_name_sequence, structure_list
- Return type:
list, list
- platipy.dicom.io.crawl.write_output_data_to_disk(output_data_dict, output_directory='./', output_file_suffix='.nii.gz', overwrite_existing_files=False)#
Write output to disk
platipy.dicom.io.nifti_to_rtstruct module#
- platipy.dicom.io.nifti_to_rtstruct.convert_nifti(dcm_path, mask_input, output_file, color_map=<matplotlib.colors.LinearSegmentedColormap object>)#
Convert a set of masks to a DICOM RTStruct object.
This function now utilises the rt-utils package: https://github.com/qurit/rt-utils We keep this function in here for compatibility
- Parameters:
dcm_path (str|pathlib.Path) – Path to the reference DICOM series
mask_input (dict|list) – A dictionary containing the name as key and image as value. Or a list of string with comma separated name and mask paths (name,path)
output_file (str|pathlib.Path) – The path to the file to write the RTStruct
color_map (matplotlib.colors.Colormap, optional) – Colormap to use for output. Defaults to matplotlib.colormaps.get_cmap(“rainbow”).
platipy.dicom.io.nifti_to_series module#
- platipy.dicom.io.nifti_to_series.convert_nifti_to_dicom_series(image, reference_dcm, tag_overrides=[], output_directory='.')#
Converts a Nifti image to a Dicom image series
- Parameters:
image (sitk.Image) – A SimpleITK image object to convert
reference_dcm (str) – A directory path containing a reference Dicom series to use
tag_overrides (list, optional) – A list of tags to override containing tuples of (key, value). Defaults to [].
output_directory (str, optional) – The directory in which to place the generated Dicom files. Defaults to “.”.
platipy.dicom.io.rtstruct_to_nifti module#
- platipy.dicom.io.rtstruct_to_nifti.convert_rtstruct(dcm_img, dcm_rt_file, prefix='Struct_', output_dir='.', output_img=None, spacing=None, replace_slashes_with='')#
Convert a DICOM RTSTRUCT to NIFTI masks.
The masks are stored as NIFTI files in the output directory
- Parameters:
dcm_img (str|pathlib.Path) – Path to the reference DICOM image series
dcm_rt_file (str|pathlib.Path) – Path to the DICOM RTSTRUCT file
prefix (str, optional) – The prefix to give the output files. Defaults to “Struct_”.
output_dir (str|pathlib.Path, optional) – Path to the output directory. Defaults to “.”.
output_img (str|pathlib.Path, optional) – If set, write the reference image to this file as in NIFTI format. Defaults to None.
spacing (list, optional) – Values of image spacing to override. Defaults to None.
replace_slashes_with (str, optional) – String to replace “/” and “” with. Set to None disable replacement of slashes. Defaults to “”.
- platipy.dicom.io.rtstruct_to_nifti.fix_missing_data(contour_data)#
Fixed a set of contour data if there are values missing
- Parameters:
contour_data (pydicom.Sequence) – The contour sequence from the DICOM object
- Returns:
The array of contour data with missing values fixed
- Return type:
np.array
- platipy.dicom.io.rtstruct_to_nifti.read_dicom_image(dicom_path)#
Read a DICOM image series
- Parameters:
dicom_path (str|pathlib.Path) – Path to the DICOM series to read
- Returns:
The image as a SimpleITK Image
- Return type:
sitk.Image
- platipy.dicom.io.rtstruct_to_nifti.read_dicom_struct_file(filename)#
Read a DICOM RTSTRUCT file
- Parameters:
filename (str|pathlib.Path) – Path to the RTSTRUCT to read
- Returns:
The RTSTRUCT as a DICOM Dataset
- Return type:
pydicom.Dataset
- platipy.dicom.io.rtstruct_to_nifti.transform_point_set_from_dicom_struct(dicom_image, dicom_struct, spacing_override=None)#
Converts a set of points from a DICOM RTSTRUCT into a mask array
- Parameters:
dicom_image (sitk.Image) – The reference image
dicom_struct (pydicom.Dataset) – The DICOM RTSTRUCT
spacing_override (list) – The spacing to override. Defaults to None
- Returns:
Returns a list of masks and a list of structure names
- Return type:
tuple