added full bgr and hsv to distribution

This commit is contained in:
Tom Selier 2023-09-29 17:56:46 +02:00
parent 14247b7d18
commit 77125a5e9c

View File

@ -47,9 +47,13 @@ def calcNormalFunc(mean, sd, len):
DATASET_PATH = "dataset\\"
BARK_TYPES = 8
averages = [[] for x in range(BARK_TYPES)]
weights = [[] for x in range(BARK_TYPES)]
variances = [[] for x in range(BARK_TYPES)]
avgs_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
wgts_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
avgs_hsv = [[[],[],[]] for x in range(BARK_TYPES)]
wgts_hsv = [[[],[],[]] for x in range(BARK_TYPES)]
labels = ["" for x in range(BARK_TYPES)]
i = -1
last_name = ""
@ -58,27 +62,44 @@ for file in os.listdir(DATASET_PATH):
if(name != last_name):
last_name = name
i += 1
labels[i] = name
image = cv2.imread(os.path.join(DATASET_PATH + file), 1)
assert image is not None, "Something went wrong"
im_bgr = cv2.imread(os.path.join(DATASET_PATH + file), 1)
assert im_bgr is not None, "Something went wrong"
im_hsv = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2HSV)
# Weighted average
averages[i].append(np.mean(image[:, :, 0]))
weights[i].append(len(image[:, :, 0]))
for j in range(3):
avgs_bgr[i][j].append(np.mean(im_bgr[:, :, j]))
wgts_bgr[i][j].append(len(im_bgr[:, :, j]))
# print()
avgs_hsv[i][j].append(np.mean(im_hsv[:, :, j]))
wgts_hsv[i][j].append(len(im_hsv[:, :, j]))
## Voor gewogen std:
## https://stackoverflow.com/questions/2413522/weighted-standard-deviation-in-numpy
weighted_avg = np.zeros(BARK_TYPES)
weighted_std = np.zeros(BARK_TYPES)
w_avg_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
w_std_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
w_avg_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
w_std_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
#TODO: Mag de weighted std berekening met avgs?
for i in range(BARK_TYPES):
weighted_avg[i] = np.average(averages[i], weights=weights[i], axis=0)
weighted_std[i] = calcWeightedStd(averages[i], weights[i])
for j in range(3):
w_avg_bgr[i][j] = np.average(avgs_bgr[i][j], weights=wgts_bgr[i][j], axis=0)
w_std_bgr[i][j] = calcWeightedStd(avgs_bgr[i][j], wgts_bgr[i][j])
print("Weighted averages: ")
print(weighted_avg)
w_avg_hsv[i][j] = np.average(avgs_hsv[i][j], weights=wgts_hsv[i][j], axis=0)
w_std_hsv[i][j] = calcWeightedStd(avgs_hsv[i][j], wgts_hsv[i][j])
print("Weighted standard deviation: ")
print(weighted_std)
for i in range(BARK_TYPES):
print("Tree: " + labels[i])
print("Weighted averages BGR: ")
print(w_avg_bgr[i])
print("Weighted standard deviation BGR: ")
print(w_std_bgr[i])
print("Weighted averages HSV: ")
print(w_avg_hsv[i])
print("Weighted standard deviation HSV: ")
print(w_std_hsv[i])
print()