:py:mod:`anomalib.post_processing.post_process` =============================================== .. py:module:: anomalib.post_processing.post_process .. autoapi-nested-parse:: Post Process This module contains utils function to apply post-processing to the output predictions. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: anomalib.post_processing.post_process.add_label anomalib.post_processing.post_process.add_normal_label anomalib.post_processing.post_process.add_anomalous_label anomalib.post_processing.post_process.anomaly_map_to_color_map anomalib.post_processing.post_process.superimpose_anomaly_map anomalib.post_processing.post_process.compute_mask .. py:function:: add_label(image: numpy.ndarray, label_name: str, color: Tuple[int, int, int], confidence: Optional[float] = None, font_scale: float = 0.005, thickness_scale=0.001) Adds a label to an image. :param image: Input image. :type image: np.ndarray :param label_name: Name of the label that will be displayed on the image. :type label_name: str :param color: RGB values for background color of label. :type color: Tuple[int, int, int] :param confidence: confidence score of the label. :type confidence: Optional[float] :param font_scale: scale of the font size relative to image size. Increase for bigger font. :type font_scale: float :param thickness_scale: scale of the font thickness. Increase for thicker font. :type thickness_scale: float :returns: Image with label. :rtype: np.ndarray .. py:function:: add_normal_label(image: numpy.ndarray, confidence: Optional[float] = None) Adds the normal label to the image. .. py:function:: add_anomalous_label(image: numpy.ndarray, confidence: Optional[float] = None) Adds the anomalous label to the image. .. py:function:: anomaly_map_to_color_map(anomaly_map: numpy.ndarray, normalize: bool = True) -> numpy.ndarray Compute anomaly color heatmap. :param anomaly_map: Final anomaly map computed by the distance metric. :type anomaly_map: np.ndarray :param normalize: Bool to normalize the anomaly map prior to applying the color map. Defaults to True. :type normalize: bool, optional :returns: [description] :rtype: np.ndarray .. py:function:: superimpose_anomaly_map(anomaly_map: numpy.ndarray, image: numpy.ndarray, alpha: float = 0.4, gamma: int = 0, normalize: bool = False) -> numpy.ndarray Superimpose anomaly map on top of in the input image. :param anomaly_map: Anomaly map :type anomaly_map: np.ndarray :param image: Input image :type image: np.ndarray :param alpha: Weight to overlay anomaly map on the input image. Defaults to 0.4. :type alpha: float, optional :param gamma: Value to add to the blended image to smooth the processing. Defaults to 0. Overall, the formula to compute the blended image is I' = (alpha*I1 + (1-alpha)*I2) + gamma :type gamma: int, optional :param normalize: whether or not the anomaly maps should be normalized to image min-max :returns: Image with anomaly map superimposed on top of it. :rtype: np.ndarray .. py:function:: compute_mask(anomaly_map: numpy.ndarray, threshold: float, kernel_size: int = 4) -> numpy.ndarray Compute anomaly mask via thresholding the predicted anomaly map. :param anomaly_map: Anomaly map predicted via the model :type anomaly_map: np.ndarray :param threshold: Value to threshold anomaly scores into 0-1 range. :type threshold: float :param kernel_size: Value to apply morphological operations to the predicted mask. Defaults to 4. :type kernel_size: int :returns: Predicted anomaly mask