mammopy package

mammopy.analysis module

class mammopy.analysis.analysis[source]

Bases: object

MASK_COLORS = ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan']
canny_edges()[source]

Detect edges using the Canny algorithm.

Parameters: image_array (numpy.ndarray): The input image array

Returns: edges (numpy.ndarray): A binary edge map with detected edges marked with 1.

Raises: TypeError: If the input image is not a numpy array.

density_estimation(img)[source]

Computes the percentage of mammogram density in an input image. Args:

model (str): The name of the pre-trained model to use. img: Input image in np.ndarray or PIL.Image format

Returns:
  • image: The image in 256*256 size used for analysis

  • pred1: The breast area of mammogram

  • pred2: The dense area of mammogram

  • percentage_density: The percentage of mammogram density in the input image.

Raises:

TypeError: If model is not a string or image_path is not a string. ValueError: If model is not a valid pre-trained model name or image_path does not point to a valid image file.

mask_to_rgba(color='red')[source]

Converts binary segmentation mask from white to red color. Also adds alpha channel to make black background transparent. Args:

mask (numpy.ndarray): [description] color (str, optional): Check MASK_COLORS for available colors. Defaults to “red”.

Returns:

numpy.ndarray: [description]

multi_density_estimation(folder_path)[source]

Computes the percentage of mammogram density in an input image. Args:

model (str): The name of the pre-trained model to use. folder_path (str): The path to the input folder of files.

Returns:

dict: A dictionary containing the results of the computation of each valid file. The dictionary has the following keys:

  • File: Name of the valid file, Skips the analysis for wrong file format

  • Non_Dense_Area: The total number of pixels in the input file that corresponse

to non-dense tissue. (i.e., non-fibroglandular) - Dense_Area: The total number of pixels in the input file that corresponse to dense tissue. (i.e., fibroglandular) - Percentage_Density: The percentage of mammogram density of the input files.

Raises:

TypeError: If model is not a string or folder_path is not a string. ValueError: If model is not a valid pre-trained model name or folder_path does not point to a valid folder.

single_density_estimation(img, visualization=False, breast_segmentation=False, dense_segmentation=False)[source]

Computes the percentage of mammogram density in an input image. Args:

model (str): The name of the pre-trained model to use. img: Input image in np.ndarray or PIL.Image format visualization: For display output breast_segmentation: Customize output to visualize Breast Area dense_segmentation: Customize output to visualize Dense Area

Returns:

dict: A dictionary containing the results of the computation. The dictionary has the following keys:

  • non_dense_area: The total number of pixels in the input image that corresponse

to non-dense tissue. (i.e., non-fibroglandular) - dense_area: The total number of pixels in the input image that corresponse to dense tissue. (i.e., fibroglandular) - percentage_density: The percentage of mammogram density in the input image.

Raises:

TypeError: If model is not a string or image_path is not a string. ValueError: If model is not a valid pre-trained model name or image_path does not point to a valid image file.

mammopy.pre_process module

class mammopy.pre_process.pre_process[source]

Bases: object

image_tensor()[source]

Converts a PIL Image or NumPy array to a PyTorch tensor. Args: - img: PIL.Image or np.ndarray, the image to be converted to a PyTorch tensor. Returns: - image: torch.Tensor, the converted PyTorch tensor. Raises: - TypeError: if the input image is not a PIL.Image or np.ndarray.

load_model()[source]

Loads a pre-trained model from a given path. Args: - model_path: str, the path to the pre-trained model.

If model_path = ‘base’, then the default pre-trained model will be loaded.

Returns: - model: torch.nn.Module, the pre-trained model loaded from the specified path. Raises: - TypeError: if the input model_path is not ‘base’.

mammopy.visualization module

class mammopy.visualization.visualization[source]

Bases: object

visualize_breast_dense_segmentation(breast_prediction_mask, dense_prediction_mask)[source]

Computes the plots of mammogram/s. Args:

image: Input image in np.ndarray breast_prediction_mask: Customize output to visualize Breast Area dense_prediction_mask: Customize output to visualize Dense Area

Returns:
Three plots:
  • Combined plot of breast and dense area.

  • Plot of breast area.

  • Plot of dense area.

Raises:

TypeError: If image is not in nd.narray format. TypeError: If breast_prediction_mask is not in nd.narray format. TypeError: If dense_prediction_mask is not in nd.narray format.