Added statistics to suite

This commit is contained in:
Tom Selier 2023-09-25 14:57:34 +02:00
parent d1bdf937db
commit 83d78c9d3f
2 changed files with 19 additions and 0 deletions

View File

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

View File

@ -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
@ -193,6 +194,13 @@ class MainApp:
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)