-
Notifications
You must be signed in to change notification settings - Fork 7
/
psnr.py
33 lines (27 loc) · 886 Bytes
/
psnr.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
import skimage
from skimage import measure
from PIL import Image
import glob
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
def compute_psnr(generated_image, original_image):
data1 = np.asarray( generated_image, dtype="float32" )
max1 = np.amax(data1)
data1 /= max1
data2 = np.asarray( original_image, dtype="float32" )
max2 = np.amax(data2)
data2 /= max2
psnr = measure.compare_psnr(data1, data2)
print('psnr: ' + str(psnr))
return psnr
def compute_ssim(generated_image,original_image):
data1 = np.asarray( generated_image, dtype="float32" )
max1 = np.amax(data1)
data1 /= max1
data2 = np.asarray( original_image, dtype="float32" )
max2 = np.amax(data2)
data2 /= max2
ssim = measure.compare_ssim(data1,data2)
print('ssim: ' + str(ssim))
return ssim