anomalib.post_processing.post_process¶
Post Process This module contains utils function to apply post-processing to the output predictions.
Module Contents¶
Functions¶
|
Adds a label to an image. |
|
Adds the normal label to the image. |
|
Adds the anomalous label to the image. |
|
Compute anomaly color heatmap. |
|
Superimpose anomaly map on top of in the input image. |
|
Compute anomaly mask via thresholding the predicted anomaly map. |
- anomalib.post_processing.post_process.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)[source]¶
Adds a label to an image.
- Parameters
image (np.ndarray) – Input image.
label_name (str) – Name of the label that will be displayed on the image.
color (Tuple[int, int, int]) – RGB values for background color of label.
confidence (Optional[float]) – confidence score of the label.
font_scale (float) – scale of the font size relative to image size. Increase for bigger font.
thickness_scale (float) – scale of the font thickness. Increase for thicker font.
- Returns
Image with label.
- Return type
np.ndarray
- anomalib.post_processing.post_process.add_normal_label(image: numpy.ndarray, confidence: Optional[float] = None)[source]¶
Adds the normal label to the image.
- anomalib.post_processing.post_process.add_anomalous_label(image: numpy.ndarray, confidence: Optional[float] = None)[source]¶
Adds the anomalous label to the image.
- anomalib.post_processing.post_process.anomaly_map_to_color_map(anomaly_map: numpy.ndarray, normalize: bool = True) numpy.ndarray[source]¶
Compute anomaly color heatmap.
- Parameters
anomaly_map (np.ndarray) – Final anomaly map computed by the distance metric.
normalize (bool, optional) – Bool to normalize the anomaly map prior to applying the color map. Defaults to True.
- Returns
[description]
- Return type
np.ndarray
- anomalib.post_processing.post_process.superimpose_anomaly_map(anomaly_map: numpy.ndarray, image: numpy.ndarray, alpha: float = 0.4, gamma: int = 0, normalize: bool = False) numpy.ndarray[source]¶
Superimpose anomaly map on top of in the input image.
- Parameters
anomaly_map (np.ndarray) – Anomaly map
image (np.ndarray) – Input image
alpha (float, optional) – Weight to overlay anomaly map on the input image. Defaults to 0.4.
gamma (int, optional) – 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
normalize – whether or not the anomaly maps should be normalized to image min-max
- Returns
Image with anomaly map superimposed on top of it.
- Return type
np.ndarray
- anomalib.post_processing.post_process.compute_mask(anomaly_map: numpy.ndarray, threshold: float, kernel_size: int = 4) numpy.ndarray[source]¶
Compute anomaly mask via thresholding the predicted anomaly map.
- Parameters
anomaly_map (np.ndarray) – Anomaly map predicted via the model
threshold (float) – Value to threshold anomaly scores into 0-1 range.
kernel_size (int) – Value to apply morphological operations to the predicted mask. Defaults to 4.
- Returns
Predicted anomaly mask