Added distribution plots

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

View File

@ -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()