forked from dali92002/DE-GAN
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount_FG_msbin.py
66 lines (46 loc) · 1.67 KB
/
count_FG_msbin.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
64
65
66
import glob
import os
import sys
import cv2 as cv
import numpy as np
# This script counts the pixels of both foregrounds (FG1 and FG2) in the labels of the MSBin dataset.
# It prints the results for each image as well as the total results as number of pixels and the percentages.
# As input, use the folder of the labels.
# usage: py count_FG_msbin.py ./your/label/folder/path
GTFolder = sys.argv[1]
def printEvaluation(fg1, fg2):
all = fg1 + fg2
print("FG1: " + str(fg1) + " (" + str((fg1 * 100)/all) + "%)")
print("FG2: " + str(fg2) + " (" + str((fg2 * 100)/all) + "%)")
def calculateValues(gt):
g = cv.imread(gt)
fg2 = cv.inRange(g, np.array([121, 121, 121]), np.array([123, 123, 123]))
fg1 = cv.inRange(g, np.array([254, 254, 254]), np.array([256, 256, 256]))
#g = cv.resize(g, (1000, 500))
#cv.imshow('ground truth', g)
#cv.waitKey(0)
#temp_fg1 = cv.resize(fg1, (1000, 500))
#cv.imshow('FG1', temp_fg1)
#cv.waitKey(0)
#temp_fg2 = cv.resize(fg2, (1000, 500))
#cv.imshow('FG2', temp_fg2)
#cv.waitKey(0)
fg1 = cv.countNonZero(fg1)
fg2 = cv.countNonZero(fg2)
return fg1, fg2
# counts the pixels for FG1 and FG2 in MSBin dataset and prints the results.
def countFG():
GTImages = glob.glob(GTFolder + '/*.png')
print("Found gt images: " + str(GTImages))
fg1Total = 0
fg2Total = 0
for gt in GTImages:
print("GT: " + os.path.basename(gt))
fg1, fg2 = calculateValues(gt)
fg1Total = fg1Total + fg1
fg2Total = fg2Total + fg2
printEvaluation(fg1, fg2)
print("\n\nTotal Results")
printEvaluation(fg1Total, fg2Total)
if __name__ == '__main__':
countFG()