tmas.src.detection ================== .. py:module:: tmas.src.detection Module Contents --------------- .. py:function:: resize_with_padding(image: numpy.ndarray, target_size: Tuple[int, int] = (512, 512), padding_color: Tuple[int, int, int] = (255, 255, 255)) -> Tuple[PIL.Image.Image, Tuple[int, int], float] 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`. :param image: The input image as a NumPy array. :type image: numpy.ndarray :param target_size: The target size for the output image. Defaults to (512, 512). :type target_size: tuple[int, int] :param padding_color: The color used for padding, specified as an RGB tuple. Defaults to white (255, 255, 255). :type padding_color: tuple[int, int, int] :return: - 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. :rtype: PIL.Image.Image, tuple[int, int], float This function also displays the padded image for debugging purposes. .. py:function:: identify_wells(image: numpy.ndarray, hough_param1: int = 20, hough_param2: int = 25, radius_tolerance: float = 0.015, verbose: bool = False) -> Union[Tuple[numpy.ndarray, numpy.ndarray], bool] 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. :param image: The input image of the microtitre plate. :type image: numpy.ndarray :param hough_param1: The first parameter for the Canny edge detector used in the Hough Circle Transform. Default is 20. :type hough_param1: int, optional :param hough_param2: 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. :type hough_param2: int, optional :param radius_tolerance: The tolerance for adjusting the radius during circle detection. Default is 0.015. :type radius_tolerance: float, optional :param verbose: If True, additional debugging information and images are displayed. Default is False. :type verbose: bool, optional :return: - 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. :rtype: 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. .. py:function:: map_predictions_to_plate_design(image: numpy.ndarray, predictions: numpy.ndarray, padding: Tuple[int, int], ratio: float, image_size: int = 512) -> List[List[str]] 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. :param image: The input image of the plate. :type image: numpy.ndarray :param predictions: A list of bounding box predictions. :type predictions: list[list[float]] :param padding: The padding applied to the image during preprocessing :type padding: tuple[int, int] :param ratio: The scaling ratio applied to the image during resizing. :type ratio: float :param image_size: The target size of the image after resizing. Default is 512x512 pixels. :type image_size: int, optional :return: 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". :rtype: list[list[str]] :raises ValueError: If the function fails to identify wells in the image. .. py:function:: post_process_detections(image: numpy.ndarray, predictions: numpy.ndarray, padding: Tuple[int, int], ratio: float) -> List[List[str]] 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. :param image: The input image of the microtitre plate. :type image: numpy.ndarray :param predictions: A list of bounding box predictions. :type predictions: list[list[float]] :param padding: The padding applied to the image during preprocessing :type padding: tuple[int, int] :param ratio: The scaling ratio applied to the image during resizing. :type ratio: float :return: 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". :rtype: list[list[str]] .. py:function:: detect_growth(image: numpy.ndarray) -> Tuple[List[List[str]], float] 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. :param image: The input image of the microtitre plate. :type image: numpy.ndarray :return: - 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. :rtype: list[list[str]], float