anomalib.post_processing.visualizer

Anomaly Visualization.

Module Contents

Classes

ImageResult

Collection of data needed to visualize the predictions for an image.

Visualizer

Class that handles the logic of composing the visualizations.

ImageGrid

Helper class that compiles multiple images into a grid using subplots.

class anomalib.post_processing.visualizer.ImageResult[source]

Collection of data needed to visualize the predictions for an image.

image :numpy.ndarray[source]
pred_score :float[source]
pred_label :str[source]
anomaly_map :Optional[numpy.ndarray][source]
gt_mask :Optional[numpy.ndarray][source]
pred_mask :Optional[numpy.ndarray][source]
heat_map :numpy.ndarray[source]
segmentations :numpy.ndarray[source]
__post_init__() None[source]

Generate heatmap overlay and segmentations, convert masks to images.

class anomalib.post_processing.visualizer.Visualizer(mode: str, task: str)[source]

Class that handles the logic of composing the visualizations.

Parameters
  • mode (str) – visualization mode, either “full” or “simple”

  • task (str) – task type, either “segmentation” or “classification”

visualize_batch(batch: Dict) Iterator[numpy.ndarray][source]

Generator that yields a visualization result for each item in the batch.

Parameters

batch (Dict) – Dictionary containing the ground truth and predictions of a batch of images.

Returns

Generator that yields a display-ready visualization for each image.

visualize_image(image_result: ImageResult) numpy.ndarray[source]

Generate the visualization for an image.

Parameters

image_result (ImageResult) – GT and Prediction data for a single image.

Returns

The full or simple visualization for the image, depending on the specified mode.

_visualize_full(image_result: ImageResult) numpy.ndarray[source]

Generate the full set of visualization for an image.

The full visualization mode shows a grid with subplots that contain the original image, the GT mask (if available), the predicted heat map, the predicted segmentation mask (if available), and the predicted segmentations (if available).

Parameters

image_result (ImageResult) – GT and Prediction data for a single image.

Returns

An image showing the full set of visualizations for the input image.

_visualize_simple(image_result: ImageResult) numpy.ndarray[source]

Generate a simple visualization for an image.

The simple visualization mode only shows the model’s predictions in a single image.

Parameters

image_result (ImageResult) – GT and Prediction data for a single image.

Returns

An image showing the simple visualization for the input image.

static show(title: str, image: numpy.ndarray, delay: int = 0) None[source]

Show an image on the screen.

Parameters
  • title (str) – Title that will be given to the window showing the image.

  • image (np.ndarray) – Image that will be shown in the window.

  • delay (int) – Delay in milliseconds to wait for keystroke. 0 for infinite.

static save(file_path: pathlib.Path, image: numpy.ndarray) None[source]

Save an image to the file system.

Parameters
  • file_path (Path) – Path to which the image will be saved.

  • image (np.ndarray) – Image that will be saved to the file system.

class anomalib.post_processing.visualizer.ImageGrid[source]

Helper class that compiles multiple images into a grid using subplots.

Individual images can be added with the add_image method. When all images have been added, the generate method must be called to compile the image grid and obtain the final visualization.

add_image(image: numpy.ndarray, title: Optional[str] = None, color_map: Optional[str] = None) None[source]

Add an image to the grid.

Parameters
  • image (np.ndarray) – Image which should be added to the figure.

  • title (str) – Image title shown on the plot.

  • color_map (Optional[str]) – Name of matplotlib color map used to map scalar data to colours. Defaults to None.

generate() numpy.ndarray[source]

Generate the image.

Returns

Image consisting of a grid of added images and their title.