-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg_score.py
61 lines (41 loc) · 1.81 KB
/
img_score.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
import imquality.brisque as brisque
import PIL.Image
import os
def calculate_scores(arg):
"""
Calculeaza scorul calitatii imaginilor aflate la path-urile primite
:param arg: poate sa fie, fie o lista de path-uri de imagini, fie un director ce contine imaginile
:return: Nothing, just prints the scores
"""
list_of_scores = []
if isinstance(arg, list):
images_path = arg
for image_path in images_path:
print("Processing image {} ...".format(image_path))
img = PIL.Image.open(image_path)
img_score = int(brisque.score(img))
list_of_scores.append(img_score)
elif os.path.isdir(arg):
images_path = os.listdir(arg)
list_of_scores = []
for image_path in images_path:
image_path = os.path.join(arg, image_path)
print("Processing image {} ...".format(image_path))
img = PIL.Image.open(image_path)
img_score = int(brisque.score(img))
list_of_scores.append(img_score)
elif os.path.isfile(arg):
img = PIL.Image.open(arg)
img_score = int(brisque.score(img))
list_of_scores = [img_score]
else:
raise Exception("Argumentul nu este nici lista, nici path de imagine, nici director!")
return list_of_scores, sum(list_of_scores) / len(list_of_scores)
# usecase 1 functia primeste o lista de path-uri catre imagini
# dict_scores_1 = calculate_scores(["C:\\Users\\Desktop\\anaaremere.jpg", "andreea.png", "alexandra.jpg"])
# usecase 2 functia primeste un nume de folder care contine path-uri de imagini
list_of_scores, avg_score = calculate_scores("100 de imagini de testat")
print(list_of_scores)
print(avg_score)
# usecase 3
# tupla = calculate_scores("andreea.png")