def _visualize_batch(self, batch: dict) -> Iterator[GeneratorResult]:
        """Yield a visualization result for each item in the batch.

        Args:
            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.

        Raises:
            TypeError: If item has neither image path nor video path defined.
        """
        for item in batch:
            if hasattr(item, "image_path") and item.image_path is not None:
                image = read_image(path=item.image_path, as_tensor=True)
                # set filename
                file_name = Path(item.image_path)
            elif hasattr(item, "video_path") and item.video_path is not None:
                image = item.original_image
                # set filename
                zero_fill = int(np.log10(item.last_frame.cpu())) + 1
                suffix = f"{str(item.frames.int().item()).zfill(zero_fill)}.png"
                file_name = Path(item.video_path) / suffix
            else:
                msg = "Item must have image path or video path defined."
                raise TypeError(msg)

            item.image = image
            if isinstance(item, VideoItem):
                image_result = ImageResult.from_dataset_item(item.to_image())
            else:
                image_result = ImageResult.from_dataset_item(item)
            yield GeneratorResult(image=self.visualize_image(image_result), file_name=file_name)
Yield a visualization result for each item in the batch.

        Args:
            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.

        Raises:
            TypeError: If item has neither image path nor video path defined.
        
src/anomalib/utils/visualization/image.py