diff --git a/src/suite.py b/src/suite.py index ab2297d..08a5721 100644 --- a/src/suite.py +++ b/src/suite.py @@ -7,6 +7,7 @@ from PIL import ImageTk, Image import numpy as np import cv2 import time +import matplotlib.pyplot as plt PROJECT_PATH = pathlib.Path(__file__).parent PROJECT_UI = "./src/gui/main.ui" @@ -16,6 +17,7 @@ class MainApp: self.builder = builder = pygubu.Builder() builder.add_resource_path(PROJECT_PATH) builder.add_from_file(PROJECT_UI) + # Main widget self.mainwindow = builder.get_object("main", master) @@ -28,7 +30,11 @@ class MainApp: self.img_path = None self.img_current = 0 self.img_max = 0 - + + # Plots + self.axs = self.createPlot(2, 2) + + # UI self.blur_rate = None self.img_size = None self.sobel_select = None @@ -69,6 +75,24 @@ class MainApp: else: print("Nothing to export!") + def createPlot(self, columns, rows): + fig, axs = plt.subplots(columns, rows) + return axs + + def drawHist(self, image, labels, column, row): + self.axs[column, row].clear() + for i,lab in enumerate(labels): + hist = cv2.calcHist( + [image], + [i], + None, + [256], + [0, 256], + ) + self.axs[column, row].plot(hist, label=lab) + self.axs[column, row].grid() + self.axs[column, row].legend() + def update(self, event=None): path = self.img_path.get() print(path) @@ -141,6 +165,24 @@ class MainApp: # Canny edge img_canny = cv2.Canny(image=img_blur,threshold1=ct1,threshold2=ct2) output.append(img_canny) + + # BGR + output.append(img[:, :, 0]) # B + output.append(img[:, :, 1]) # G + output.append(img[:, :, 2]) # R + if img is not None: + self.drawHist(img, ('B', 'G', 'R'), 0, 0) + + # HSV + img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) + output.append(img_hsv) + output.append(img_hsv[:, :, 0]) # H + output.append(img_hsv[:, :, 1]) # S + output.append(img_hsv[:, :, 2]) # V + if img_hsv is not None: + self.drawHist(img_hsv, ('H', 'S', 'V'), 0, 1) + + plt.show(block=False) # Draw all output images for idx, data in enumerate(output):