:py:mod:`anomalib.post_processing.visualizer` ============================================= .. py:module:: anomalib.post_processing.visualizer .. autoapi-nested-parse:: Anomaly Visualization. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: anomalib.post_processing.visualizer.ImageResult anomalib.post_processing.visualizer.Visualizer anomalib.post_processing.visualizer.ImageGrid .. py:class:: ImageResult Collection of data needed to visualize the predictions for an image. .. py:attribute:: image :annotation: :numpy.ndarray .. py:attribute:: pred_score :annotation: :float .. py:attribute:: pred_label :annotation: :str .. py:attribute:: anomaly_map :annotation: :numpy.ndarray .. py:attribute:: gt_mask :annotation: :Optional[numpy.ndarray] .. py:attribute:: pred_mask :annotation: :Optional[numpy.ndarray] .. py:attribute:: heat_map :annotation: :numpy.ndarray .. py:attribute:: segmentations :annotation: :numpy.ndarray .. py:method:: __post_init__(self) Generate heatmap overlay and segmentations, convert masks to images. .. py:class:: Visualizer(mode: str, task: str) Class that handles the logic of composing the visualizations. :param mode: visualization mode, either "full" or "simple" :type mode: str :param task: task type, either "segmentation" or "classification" :type task: str .. py:method:: visualize_batch(self, batch: Dict) -> Iterator[numpy.ndarray] Generator that yields a visualization result for each item in the batch. :param batch: Dictionary containing the ground truth and predictions of a batch of images. :type batch: Dict :returns: Generator that yields a display-ready visualization for each image. .. py:method:: visualize_image(self, image_result: ImageResult) -> numpy.ndarray Generate the visualization for an image. :param image_result: GT and Prediction data for a single image. :type image_result: ImageResult :returns: The full or simple visualization for the image, depending on the specified mode. .. py:method:: _visualize_full(self, image_result: ImageResult) 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). :param image_result: GT and Prediction data for a single image. :type image_result: ImageResult :returns: An image showing the full set of visualizations for the input image. .. py:method:: _visualize_simple(self, image_result) Generate a simple visualization for an image. The simple visualization mode only shows the model's predictions in a single image. :param image_result: GT and Prediction data for a single image. :type image_result: ImageResult :returns: An image showing the simple visualization for the input image. .. py:method:: show(title: str, image: numpy.ndarray, delay: int = 0) :staticmethod: Show an image on the screen. :param title: Title that will be given to the window showing the image. :type title: str :param image: Image that will be shown in the window. :type image: np.ndarray :param delay: Delay in milliseconds to wait for keystroke. 0 for infinite. :type delay: int .. py:method:: save(file_path: pathlib.Path, image: numpy.ndarray) :staticmethod: Save an image to the file system. :param file_path: Path to which the image will be saved. :type file_path: Path :param image: Image that will be saved to the file system. :type image: np.ndarray .. py:class:: ImageGrid 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. .. py:method:: add_image(self, image: numpy.ndarray, title: Optional[str] = None, color_map: Optional[str] = None) Add an image to the grid. :param image: Image which should be added to the figure. :type image: np.ndarray :param title: Image title shown on the plot. :type title: str :param color_map: Name of matplotlib color map used to map scalar data to colours. Defaults to None. :type color_map: Optional[str] .. py:method:: generate(self) -> numpy.ndarray Generate the image. :returns: Image consisting of a grid of added images and their title.