Utils¶
Contour related util functions
-
munge.utils.contour.
get_dcm_num_for_contour
(contour_file_name)¶ Gets the DICOM series number for a given contour file name or full file path
Ex: For ‘data/contourfiles/SC-HF-I-1/i-contours/IM-0001-0048-icontour-manual.txt’ the return value will be 48
Parameters: contour_file_name – name of the contour file Returns: Integer corresponding to the DICOM series number
-
munge.utils.contour.
parse_contour_file
(filename)¶ Parse the given contour filename
Parameters: filename – filepath to the contourfile to parse Returns: list of tuples holding x, y coordinates of the contour
-
munge.utils.contour.
poly_to_mask
(polygon, width, height)¶ Convert polygon to mask
Parameters: - polygon – list of pairs of x, y coords [(x1, y1), (x2, y2), …] in units of pixels
- width – scalar image width
- height – scalar image height
Returns: Boolean mask of shape (height, width)
Image related util functions
-
munge.utils.image.
get_dcm_resolution
(dcm_img)¶ Gets the resolution of the DICOM image
Parameters: dcm_img – pydicom instance of DICOM image Returns: Resolution of the DICOM image i.e equivalent spacing of 1 pixel in millimeters
-
munge.utils.image.
grayscale_to_rgb
(img_raw)¶ Converts the given grayscale image to a three channel image
Parameters: img_raw – the raw grayscale image Returns: 3 Channel RGB image
-
munge.utils.image.
parse_dicom_file
(filename)¶ Parse the given DICOM filename
Parameters: filename – filepath to the DICOM file to parse Returns: dictionary with DICOM image data
Miscellaneous util functions
-
munge.utils.misc.
csv2dict
(csv_file)¶ Converts and returns a CSV file to Dict
Parameters: csv_file – Path to the CSV file Returns: Dict representation of the CSV file
-
munge.utils.misc.
get_app_config
(config_file)¶ Gets the application configuration as a dict from the given file
Parameters: config_file – path to the configuration file Returns: Dict containing the application configuration
-
munge.utils.misc.
get_bounding_box_coords
(contour, window=30)¶ Given a contour and window, get the min and max co-ordinates of a bounding box around that window
Parameters: - contour – Array of co-ordinates defining the contour
- window – The window size of the bounding box
Returns: min_x, max_x, min_y and max_y of the bounding box
-
munge.utils.misc.
get_ocontour_for_icontour
(icontour_file, ocontour_dir)¶ Gets the ocontour file corresponding to the given icontour_path. If the ocontour file does not exist, None is returned.
Parameters: icontour_path – Full path to the icontour file Returns: Path of the corresponding ocontour file, if exists or None
-
munge.utils.misc.
get_uuid
()¶ Generates and returns a random GUID
Returns: Random GUID V4