From 015a1a97f280a3054103fce82349321c26d56d12 Mon Sep 17 00:00:00 2001 From: Alexander Riedel <54716527+alexriedel1@users.noreply.github.com> Date: Thu, 25 Apr 2024 19:59:05 +0200 Subject: [PATCH] denorm image visualizer --- src/anomalib/utils/visualization/image.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/anomalib/utils/visualization/image.py b/src/anomalib/utils/visualization/image.py index ddcfd416fb..13c0173707 100644 --- a/src/anomalib/utils/visualization/image.py +++ b/src/anomalib/utils/visualization/image.py @@ -136,11 +136,19 @@ def _visualize_batch(self, batch: dict) -> Iterator[GeneratorResult]: Returns: Generator that yields a display-ready visualization for each image. """ + from torchvision.transforms.v2 import Normalize + import torch + + mean = torch.tensor([0.485, 0.456, 0.406], dtype=torch.float32) + std = torch.tensor([0.229, 0.224, 0.225], dtype=torch.float32) + denorm = Normalize((-mean / std).tolist(), (1.0 / std).tolist()) + batch_size = batch["image"].shape[0] for i in range(batch_size): if "image_path" in batch: height, width = batch["image"].shape[-2:] - image = (read_image(path=batch["image_path"][i]) * 255).astype(np.uint8) + image = (denorm(batch["image"][i])*255).cpu().numpy().astype(np.uint8) #(read_image(path=batch["image_path"][i]) * 255).astype(np.uint8) + image = np.transpose(image, (1, 2, 0)) image = cv2.resize(image, dsize=(width, height), interpolation=cv2.INTER_AREA) elif "video_path" in batch: height, width = batch["image"].shape[-2:]