From b44cad7102082b5ca80d38a9e35d85691bc20403 Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Fri, 29 Sep 2023 18:23:33 +0200 Subject: [PATCH] Added distribution plots --- .../algorithms/distribution_test.py | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/experiments/algorithms/distribution_test.py b/src/experiments/algorithms/distribution_test.py index 58cfcb2..30e2ca6 100644 --- a/src/experiments/algorithms/distribution_test.py +++ b/src/experiments/algorithms/distribution_test.py @@ -3,21 +3,6 @@ import matplotlib.pyplot as plt import cv2 import os import math - -def imgStats(img): - mean = np.zeros(3) - std = np.zeros(3) - for i in range(img.shape[2]): - mean[i] = np.mean(img[:, :, i]) - std[i] = np.std(img[:, :, i]) - return mean, std - -def isFloat(num): - try: - float(num) - return True - except ValueError: - return False def calcWeightedStd(values, weights): N = len(values) @@ -81,7 +66,7 @@ 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? +#TODO: Mag de weighted std berekening met avgs? Denk t nie for i in range(BARK_TYPES): for j in range(3): w_avg_bgr[i][j] = np.average(avgs_bgr[i][j], weights=wgts_bgr[i][j], axis=0) @@ -90,16 +75,24 @@ for i in range(BARK_TYPES): 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]) + +fig, axs = plt.subplots(2,4) +row = 0 +col = -1 +colours = ('b', 'g', 'r') 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]) + row = 1 if i > 3 else 0 + col += 1 + if i == 4: col = 0 - print("Weighted averages HSV: ") - print(w_avg_hsv[i]) - print("Weighted standard deviation HSV: ") - print(w_std_hsv[i]) - print() + for j in range(3): + f = calcNormalFunc(w_avg_bgr[i][j], w_std_bgr[i][j], 255) + label = "$\mu:$ %d, $\sigma: %d$"%(w_avg_bgr[i][j],w_std_bgr[i][j]) + axs[row, col].plot(f, c=colours[j], label=label) + + axs[row, col].grid() + axs[row, col].legend() + axs[row, col].set_title(str(labels[i])) + +plt.show()