diff --git a/src/helpers/statistics.py b/src/helpers/statistics.py new file mode 100644 index 0000000..c92e061 --- /dev/null +++ b/src/helpers/statistics.py @@ -0,0 +1,9 @@ +import numpy as np + +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 \ No newline at end of file diff --git a/src/suite.py b/src/suite.py index 2242a05..c04a365 100644 --- a/src/suite.py +++ b/src/suite.py @@ -9,6 +9,7 @@ import cv2 import time import matplotlib.pyplot as plt import json +from helpers.statistics import imgStats ## UI config load PROJECT_PATH = pathlib.Path(__file__).parent @@ -192,6 +193,13 @@ class MainApp: self.axs[column, row].imshow(results) self.axs[column, row].xaxis.set_major_formatter(lambda x, pos: str(x*canny_step)) self.axs[column, row].yaxis.set_major_formatter(lambda x, pos: str(x*canny_step)) + + def writeStats(self, img, labels, column, row): + mean, std = imgStats(img) + self.axs[column, row].title.set_text( + "mean: %c:%d %c:%d %c:%d \n std: %c:%d %c:%d %c:%d" + %(labels[0], mean[0], labels[1], mean[1], labels[2], mean[2], + labels[0], std[0], labels[1], std[1], labels[2], std[2])) def update(self, event=None): path = self.img_path.get() @@ -258,6 +266,7 @@ class MainApp: if img is not None: self.drawHist(img, ('B', 'G', 'R'), 0, 0) + self.writeStats(img, ('B', 'G', 'R'), 0, 0) # HSV img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) @@ -268,6 +277,7 @@ class MainApp: if img_hsv is not None: self.drawHist(img_hsv, ('H', 'S', 'V'), 0, 1) + self.writeStats(img_hsv, ('H', 'S', 'V'), 0, 1) # Canny Heatmap self.drawCannyHM(img, 1, 1)