-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
27 lines (21 loc) · 855 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import matplotlib.pyplot as plt
import torchvision.transforms as T
import torch
from skimage.metrics import structural_similarity
def display_image(image, figsize=(3, 3), save_image=False, name=None):
plt.figure(figsize=figsize)
if torch.is_tensor(image):
to_pil_image = T.ToPILImage()
image = to_pil_image(image)
plt.imshow(image, cmap='gray')
if save_image == True:
plt.savefig(name)
plt.show()
def display_heat_map(image1, image2, save_image=False, name=None):
_, _, S = structural_similarity(image1.detach().cpu().numpy()[1:-1, 1:-1], image2.detach().cpu().numpy()[1:-1, 1:-1], gradient=True, full=True, multichannel=False)
heat_map = 1-S
plt.imshow(heat_map, vmax=1, cmap="jet")
plt.colorbar()
if save_image == True:
plt.savefig(name)
plt.show()