tmas.detection

Module Contents

tmas.detection.resize_with_padding(image, target_size=(512, 512), padding_color=(255, 255, 255))[source]

Resize an image while maintaining its aspect ratio,

This function resizes the input image so that it fits within the specified target_size while preserving the original aspect ratio. It then pads the resized image with a specified padding_color to match the target_size.

Parameters:
  • image (numpy.ndarray) – The input image as a NumPy array.

  • target_size (tuple[int, int]) – The target size for the output image. Defaults to (512, 512).

  • padding_color (tuple[int, int, int]) – The color used for padding, specified as an RGB tuple. Defaults to white (255, 255, 255).

Returns:

  • new_image (PIL.Image.Image): The resized and padded image.

  • padding (tuple[int, int]): The padding applied to the left/right and top/bottom.

  • ratio (float): The scaling ratio used to resize the image.

Return type:

PIL.Image.Image, tuple[int, int], float

This function also displays the padded image for debugging purposes.

tmas.detection.identify_wells(image, hough_param1=20, hough_param2=25, radius_tolerance=0.015, verbose=False)[source]

Identify the wells on a microtitre plate image.

This function detects the circular wells on a microtitre plate image, computes their centers and radii, and returns this information if the correct number of wells is identified. The function assumes a standard 8x12 well layout.

Parameters:
  • image (numpy.ndarray) – The input image of the microtitre plate.

  • hough_param1 (int, optional) – The first parameter for the Canny edge detector used in the Hough Circle Transform. Default is 20.

  • hough_param2 (int, optional) – The second parameter for the Hough Circle Transform, which controls the minimum number of edge points required to consider a circle valid. Default is 25.

  • radius_tolerance (float, optional) – The tolerance for adjusting the radius during circle detection. Default is 0.015.

  • verbose (bool, optional) – If True, additional debugging information and images are displayed. Default is False.

Returns:

  • well_center (numpy.ndarray): A 2D array with the (x, y) coordinates of the

    centers of the detected wells.

  • well_radii (numpy.ndarray): A 2D array with the radii of the detected wells.

If the correct number of wells is not detected, the function returns False.

Return type:

numpy.ndarray, numpy.ndarray or bool

Raises:

ValueError – If the image is not in a valid format (grayscale or RGB) or if the image is empty after processing.

tmas.detection.map_predictions_to_plate_design(image, predictions, padding, ratio, image_size=512)[source]

Map object detection predictions to the corresponding wells in a microtitre plate design.

This function takes an image of a plate, along with bounding box predictions from an object detection model, and maps these predictions to the appropriate wells on the plate. The function returns a growth matrix indicating which wells show signs of growth.

Parameters:
  • image (numpy.ndarray) – The input image of the plate.

  • predictions (list[list[float]]) – A list of bounding box predictions.

  • padding (tuple[int, int]) – The padding applied to the image during preprocessing

  • ratio (float) – The scaling ratio applied to the image during resizing.

  • image_size (int, optional) – The target size of the image after resizing. Default is 512x512 pixels.

Returns:

A growth matrix indicating the growth status for each well on the plate. Each entry in the matrix is either “-none-” (no growth) or “growth”.

Return type:

list[list[str]]

Raises:

ValueError – If the function fails to identify wells in the image.

tmas.detection.post_process_detections(image, predictions, padding, ratio)[source]

Post-process the detection predictions and map them to the plate design.

This function takes the bounding box predictions from the object detection model and maps them to the corresponding wells on the microtitre plate, resulting in a growth matrix that indicates which wells exhibit growth.

Parameters:
  • image (numpy.ndarray) – The input image of the microtitre plate.

  • predictions (list[list[float]]) – A list of bounding box predictions.

  • padding (tuple[int, int]) – The padding applied to the image during preprocessing

  • ratio (float) – The scaling ratio applied to the image during resizing.

Returns:

A growth matrix indicating the growth status for each well on the plate. Each entry in the matrix is either “-none-” (no growth) or “growth”.

Return type:

list[list[str]]

tmas.detection.detect_growth(image)[source]

Detect bacterial growth on a plate image using object detection model.

This function resizes the input image with padding, converts it to grayscale, and then uses a model to detect bacterial growth. The detected bounding boxes are post-processed to map the predictions to the corresponding wells on the plate, resulting in a growth matrix.

Parameters:

image (numpy.ndarray) – The input image of the microtitre plate.

Returns:

  • growth_matrix (list[list[str]]): A matrix indicating growth status in each well.

  • inference_time (float): The time taken to perform the inference in milliseconds.

Return type:

list[list[str]], float