-
Notifications
You must be signed in to change notification settings - Fork 10
/
BRISQUE.py
63 lines (49 loc) · 1.69 KB
/
BRISQUE.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Example run: python -W ignore BRISQUE.py --test_dir /root/autodl-tmp/Result/RetinexNet/ExDark --read_subfolder True
import os
from glob import glob
from PIL import Image
import numpy as np
from skimage import io, img_as_float
import imquality.brisque as brisque
import argparse
from tqdm import tqdm
def parse_args():
parser = argparse.ArgumentParser(description='')
parser.add_argument('--test_dir', type=str,
help='directory for testing inputs')
parser.add_argument('--read_subfolder', type=bool, default=False)
args = parser.parse_args()
return args
def cal_loe(inp):
pass
def cal_brisque(inp, i, AssertionError_count):
imgOri = Image.open(inp)
img = img_as_float(imgOri)
try:
score = brisque.score(img)
except AssertionError:
score = 0
AssertionError_count += 1
print(i, " path[i] is", inp)
return score, AssertionError_count
def main(args):
if args.read_subfolder:
path = glob(os.path.join(args.test_dir, '*/*'))
else:
path = glob(os.path.join(args.test_dir, '*'))
list_brisque = []
AssertionError_count = 0
for i in range(len(path)):
# for i in tqdm(range(1550, len(path))):
# calculate scores
# print(i, " path[i] is", path[i])
score, AssertionError_count = cal_brisque(path[i], i, AssertionError_count)
if score != 0:
# append to list
list_brisque.append(score)
# Average score for the dataset
print("Have ", AssertionError_count, " times AssertionError.")
print("Average BRISQUE:", "%.3f" % (np.mean(list_brisque)))
if __name__ == "__main__":
args = parse_args()
main(args)