-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreOutput.py
62 lines (44 loc) · 1.8 KB
/
scoreOutput.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
"""
Scores the output images in the directories.output directory.
"""
import numpy as np
import matplotlib.pyplot as plt
import cv2
import directories
from visualization import *
def greyscale(img):
return np.average(img, 2)
def threshold(arr, threshold):
arr[arr<threshold] = 0
arr[arr != 0] = 255
return arr
def main():
output = directories.loadImagesInFolder(directories.output)
output = np.asarray(output)
groundTruth = directories.loadImagesInFolder(directories.groundTruth)
groundTruth = np.asarray(groundTruth)
print("")
print("Name\t\tYour dif")
l = []
for outputImage in output:
#Find the corresponding groundTruth image
fname = outputImage[1]
groundTruthImage = groundTruth[groundTruth[:, 1] == fname][0][0]
#Now compare the output with the ground truth
groundTruthImage = greyscale(groundTruthImage)
pixelsTotal = groundTruthImage.size
outputImage = np.asarray(outputImage[0])
outputImage = greyscale(outputImage)
threshold(outputImage, 150)
assert groundTruthImage.shape == outputImage.shape
pixelsDifferent = np.count_nonzero(outputImage != groundTruthImage)
fractionDifferent = float(pixelsDifferent)/pixelsTotal
#pixels2Different = np.count_nonzero(output2Image != groundTruthImage)
#print(fname + ": \t" + "{:.0%}".format(fractionDifferent))# + ": \t\t" + "{:.0%}".format(float(pixels2Different)/pixelsTotal))
#visualize(outputImage - groundTruthImage)
l.append((fractionDifferent, fname))
for fractionDifferent, fname in sorted(l):
print(fname + ": \t" + "{:.1%}".format(fractionDifferent))# + ": \t\t" + "{:.0%}".format(float(pixels2Different)/pixelsTotal))
return l
if __name__ == "__main__":
main()