Added distribution plots

This commit is contained in:
Tom Selier 2023-09-29 18:23:33 +02:00
parent 77125a5e9c
commit b44cad7102

View File

@ -4,21 +4,6 @@ import cv2
import os import os
import math 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): def calcWeightedStd(values, weights):
N = len(values) N = len(values)
x_bar = np.average(values, weights=weights, axis=0) x_bar = np.average(values, weights=weights, axis=0)
@ -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_avg_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
w_std_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 i in range(BARK_TYPES):
for j in range(3): for j in range(3):
w_avg_bgr[i][j] = np.average(avgs_bgr[i][j], weights=wgts_bgr[i][j], axis=0) 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_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]) 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): for i in range(BARK_TYPES):
print("Tree: " + labels[i]) row = 1 if i > 3 else 0
print("Weighted averages BGR: ") col += 1
print(w_avg_bgr[i]) if i == 4: col = 0
print("Weighted standard deviation BGR: ")
print(w_std_bgr[i])
print("Weighted averages HSV: ") for j in range(3):
print(w_avg_hsv[i]) f = calcNormalFunc(w_avg_bgr[i][j], w_std_bgr[i][j], 255)
print("Weighted standard deviation HSV: ") label = "$\mu:$ %d, $\sigma: %d$"%(w_avg_bgr[i][j],w_std_bgr[i][j])
print(w_std_hsv[i]) axs[row, col].plot(f, c=colours[j], label=label)
print()
axs[row, col].grid()
axs[row, col].legend()
axs[row, col].set_title(str(labels[i]))
plt.show()