forked from fengzhang427/HEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_Metrics.py
40 lines (35 loc) · 1.31 KB
/
test_Metrics.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 PIL import Image
import numpy as np
import os
import skimage.metrics
from torchvision import transforms
from utils import load_images, load_images_no_norm
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
def test(image_path, gt_path):
filelist = os.listdir(testfolder)
psnr_total = 0
ssim_total = 0
count = 0
for i, file in enumerate(filelist):
print(file)
testmat = Image.open(os.path.join(testfolder + '/' + file)).convert('RGB')
testmat = np.array(testmat)
gtmat = Image.open(os.path.join(gtfolder + '/' + file)).convert('RGB')
gtmat = np.array(gtmat)
# testmat = load_images_no_norm(os.path.join(testfolder + '/' + file))
# gtmat = load_images_no_norm(os.path.join(gtfolder + '/' + file))
# w, h, _ = testmat.shape
# gtmat = gtmat[0:w, 0:h, :]
psnr = skimage.metrics.peak_signal_noise_ratio(testmat, gtmat)
ssim = skimage.metrics.structural_similarity(testmat, gtmat, multichannel=True)
psnr_total += psnr
ssim_total += ssim
print(ssim)
print(psnr)
count += 1
print(count)
print('mean psnr: {}, ssim:{}'.format(psnr_total / count, ssim_total / count))
if __name__ == "__main__":
testfolder = './NDM_LOL/'
gtfolder = '/home/dancer/LOL/test_gt'
test(testfolder, gtfolder)