Mask manager module

This module is responsible for creating and applying the masks. The idea and lots of the code were very heavily borrowed from this study: https://www.cis.upenn.edu/~jshi/ped_html/

class library.image_manipulation.mask_manager.MaskManager

Bases: object

Class containing all methods related to image masks This class is used to create masks for each tiff image (post-extraction from czi files), apply user-modified masks

Note: Uses pytorch for ML generation of masks

apply_user_mask_edits()

Apply the edits made on the image masks to extract the tissue from the surround debris to create the final masks used to clean the images. Input dir is the colored merged masks Remove the binary mask files as they might be stale.

create_colored_mask_qc()

Create masks for the downsampled images using a machine learning algorithm. The input files are the files that have been normalized. The output files are the colored merged files.

create_contour_mask()

Create masks for the downsampled images using contours The input files are the files that have not been normalized The output files are the colored merged files.

create_full_resolution_mask()

Upsample the masks created for the downsampled images to the full resolution

create_mask()

Helper method to call either full resolition of downsampled. Create the images masks for extracting the tissue from the surrounding debris using a CNN based machine learning algorithm. If the images are from the MDXXX brains, they are 3 dimenions so the masks need to be done differently

get_model_instance_segmentation(num_classes)

This loads the mask model CNN

Parameters:

num_classes – int showing how many classes, usually 2, brain tissue, not brain tissue

get_model_instance_segmentationTESTING(num_classes)

This loads the mask model CNN

Parameters:

num_classes – int showing how many classes, usually 2, brain tissue, not brain tissue

load_machine_learning_model()

Load the CNN model used to generate image masks

static remove_small_contours(raw_img, debug=False)

Removes small contours from the given image. This function processes the input image to find and remove contours that are smaller than a predefined area threshold. Optionally, it can also annotate the image with contour area values and bounding rectangles for debugging purposes. Args: :param raw_img (numpy.ndarray): The input image in which contours are to be detected and removed. :param debug (bool, optional): If True, the function will annotate the image with contour area values and bounding rectangles. Defaults to False. return: numpy.ndarray: The processed image with small contours removed.

static resize_tif(file_key)

Function to upsample mask images

Parameters:

file_key – tuple of inputs to the upsampling program including:

  • path to thumbnail file

  • The output directory of upsampled image

  • resulting size after upsampling