added full bgr and hsv to distribution
This commit is contained in:
parent
14247b7d18
commit
77125a5e9c
@ -47,9 +47,13 @@ def calcNormalFunc(mean, sd, len):
|
|||||||
DATASET_PATH = "dataset\\"
|
DATASET_PATH = "dataset\\"
|
||||||
BARK_TYPES = 8
|
BARK_TYPES = 8
|
||||||
|
|
||||||
averages = [[] for x in range(BARK_TYPES)]
|
avgs_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||||
weights = [[] for x in range(BARK_TYPES)]
|
wgts_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||||
variances = [[] 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
|
i = -1
|
||||||
last_name = ""
|
last_name = ""
|
||||||
@ -58,27 +62,44 @@ for file in os.listdir(DATASET_PATH):
|
|||||||
if(name != last_name):
|
if(name != last_name):
|
||||||
last_name = name
|
last_name = name
|
||||||
i += 1
|
i += 1
|
||||||
|
labels[i] = name
|
||||||
|
|
||||||
image = cv2.imread(os.path.join(DATASET_PATH + file), 1)
|
im_bgr = cv2.imread(os.path.join(DATASET_PATH + file), 1)
|
||||||
assert image is not None, "Something went wrong"
|
assert im_bgr is not None, "Something went wrong"
|
||||||
|
im_hsv = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2HSV)
|
||||||
|
|
||||||
# Weighted average
|
for j in range(3):
|
||||||
averages[i].append(np.mean(image[:, :, 0]))
|
avgs_bgr[i][j].append(np.mean(im_bgr[:, :, j]))
|
||||||
weights[i].append(len(image[:, :, 0]))
|
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
|
w_avg_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||||
weighted_avg = np.zeros(BARK_TYPES)
|
w_std_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||||
weighted_std = np.zeros(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):
|
for i in range(BARK_TYPES):
|
||||||
weighted_avg[i] = np.average(averages[i], weights=weights[i], axis=0)
|
for j in range(3):
|
||||||
weighted_std[i] = calcWeightedStd(averages[i], weights[i])
|
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: ")
|
w_avg_hsv[i][j] = np.average(avgs_hsv[i][j], weights=wgts_hsv[i][j], axis=0)
|
||||||
print(weighted_avg)
|
w_std_hsv[i][j] = calcWeightedStd(avgs_hsv[i][j], wgts_hsv[i][j])
|
||||||
|
|
||||||
print("Weighted standard deviation: ")
|
for i in range(BARK_TYPES):
|
||||||
print(weighted_std)
|
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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user