-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
40 lines (29 loc) · 1017 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
28
29
30
31
32
33
34
35
36
37
38
39
40
from skimage.metrics import structural_similarity
from skimage.metrics import peak_signal_noise_ratio
import numpy as np
def batch_ssim(a,b):
ssim_values = []
if not isinstance(b, np.ndarray):
b = b.numpy()
for a, b in zip(a, b):
ssim_val = structural_similarity(a, b, data_range = 1)
ssim_values.append(ssim_val)
return np.mean(ssim_values)
def batch_ssim_full(a,b):
ssim_values = []
ssim_maps = []
if not isinstance(b, np.ndarray):
b = b.numpy()
for a, b in zip(a, b):
ssim_val, ssim_map = structural_similarity(a, b, full = True, data_range = 1)
ssim_values.append(ssim_val)
ssim_maps.append(ssim_map)
return np.mean(ssim_values), ssim_maps
def batch_psnr(a,b):
psnr_values = []
if not isinstance(b, np.ndarray):
b = b.numpy()
for a, b in zip(a, b):
psnr_val = peak_signal_noise_ratio(a, b, data_range = 1)
psnr_values.append(psnr_val)
return np.mean(psnr_values)