diff --git a/src/helpers/gui/main.ui b/src/helpers/gui/main.ui index 27b05d0..a410225 100644 --- a/src/helpers/gui/main.ui +++ b/src/helpers/gui/main.ui @@ -34,7 +34,7 @@ int:canny_thr1 - 1 + 2 0 1 @@ -44,7 +44,7 @@ Canny thresh. 1 - 1 + 2 0 @@ -57,7 +57,7 @@ int:canny_thr2 - 2 + 3 1 1 @@ -67,7 +67,7 @@ Canny thresh. 2 - 2 + 3 1 5 0 @@ -84,9 +84,9 @@ 0 - 1 + 2 30 - 7 + 6 1 @@ -100,6 +100,7 @@ 0 + 2 60 0 3 @@ -111,6 +112,7 @@ Contrast adjust 0 + 2 2 @@ -123,7 +125,7 @@ int:img_size - 1 + 2 2 60 3 @@ -135,7 +137,7 @@ Display size adjust - 1 + 2 2 2 1 @@ -148,10 +150,10 @@ x y both - 0 + 1 1 - 42 - 5 + 4 + 1 @@ -171,9 +173,9 @@ < Prev img - 1 + 2 10 - 5 + 4 1 @@ -183,9 +185,9 @@ Next img > - 2 + 3 10 - 5 + 4 1 @@ -195,10 +197,10 @@ Export PNG - 2 + 3 1 10 - 7 + 6 1 @@ -208,8 +210,8 @@ int:export_id 15 - 1 - 7 + 2 + 6 @@ -217,9 +219,9 @@ Export Image by ID - 1 + 2 2 - 6 + 5 @@ -235,7 +237,7 @@ 25 word - 3 + 4 1 0 8 @@ -251,6 +253,7 @@ 0 + 2 60 1 @@ -261,6 +264,7 @@ Brightness adjust 0 + 2 0 @@ -270,17 +274,8 @@ Dataset path 0 - 6 - - - - - - Image control - - 1 2 - 4 + 5 @@ -289,10 +284,10 @@ Export ID for entire dataset - 1 + 2 2 30 - 8 + 7 @@ -301,7 +296,20 @@ TkIconFont Powered by ARNweb.nl & TomSelier.com - 0 + 4 + 2 + 8 + + + + + + Run analysis for entire dataset (!) + + + 2 + 2 + 15 8 diff --git a/src/helpers/logger.py b/src/helpers/logger.py index c624726..a770899 100644 --- a/src/helpers/logger.py +++ b/src/helpers/logger.py @@ -37,7 +37,9 @@ class Logger: self.file.write(self.csv(self.index)) self.file.write(self.csv(self.data)) - + self.clear() + + def clear(self): # Clear data self.index = [] self.data = [] diff --git a/src/suite.py b/src/suite.py index cb0cab4..d486684 100644 --- a/src/suite.py +++ b/src/suite.py @@ -2,7 +2,7 @@ import pathlib import pygubu import glob -from tkinter import * +import tkinter from PIL import ImageTk, Image import numpy as np import cv2 @@ -27,7 +27,6 @@ config_json = json.load(config_file) log = Logger(config_json["out"]) - ## UI class setup class MainApp: def __init__(self, master=None): @@ -151,26 +150,26 @@ class MainApp: else: print("Nothing to export!") - def apply_all(self, event=None): + def apply_all(self, event=None, export = True): """ Export given preprocess id for every image in the dataset folder """ img_id = self.export_id.get() img_current = copy.deepcopy(self.img_current) - now = datetime.datetime.now() - path = pathlib.Path( - config_json["out"], - f"{self.output[1][img_id]}-all-{now.strftime('%Y-%m-%dT%H.%M.%S')}/", - ) - os.mkdir(path) + if (export): + now = datetime.datetime.now() + path = pathlib.Path( + config_json["out"], + f"{self.output[1][img_id]}-all-{now.strftime('%Y-%m-%dT%H.%M.%S')}/", + ) + os.mkdir(path) while True: self.img_next() - self.update( - part_update=True - ) # Enforce partial update since we don't need the histograms etc. - self.apply(path=path) + + if (export): + self.apply(path=path) if self.img_current == img_current: break @@ -178,6 +177,9 @@ class MainApp: ## Ensure display is always correct with image self.update() + def analyse_all(self, event=None): + self.apply_all(export=False) + def add_output(self, data, name: str): """ Add CV2 image to canvas output @@ -196,9 +198,9 @@ class MainApp: # Clear previously printed images self.tk_imgs = [] - self.meta.config(state=NORMAL) - self.meta.delete(1.0, END) - self.meta.insert(END, f"{self.img_name}\n") + self.meta.config(state=tkinter.NORMAL) + self.meta.delete(1.0, tkinter.END) + self.meta.insert(tkinter.END, f"{self.img_name}\n") # Draw all output images for idx, data in enumerate(self.output[0]): @@ -214,15 +216,15 @@ class MainApp: self.canvas.configure(height=(drawY + size)) self.canvas.create_image( - drawX, drawY, anchor=NW, image=self.tk_imgs[idx], tags="og" + drawX, drawY, anchor=tkinter.NW, image=self.tk_imgs[idx], tags="og" ) drawX += size # Add name to text box - self.meta.insert(END, f"{idx}: {self.output[1][idx]}\n") + self.meta.insert(tkinter.END, f"{idx}: {self.output[1][idx]}\n") # Clear output - self.meta.config(state=DISABLED) + self.meta.config(state=tkinter.DISABLED) def createPlot(self, columns, rows): fig, axs = plt.subplots(columns, rows) @@ -284,7 +286,8 @@ class MainApp: log.add("Canny Std", np.matrix(results).std()) log.add("Canny Min", np.matrix(results).min()) log.add("Canny Max", np.matrix(results).max()) - # log.add("Canny Diff max", np.diff(func)) + log.add("Canny Diff min", np.diff(func).min()) + log.add("Canny Diff max", np.diff(func).max()) def writeStats(self, img, labels, column, row): mean, std = imgStats(img) @@ -310,13 +313,11 @@ class MainApp: log.add(f"Mean {label}", mean[idx]) log.add(f"Std {label}", std[idx]) - def update(self, event=None, part_update=False): + def update(self, event=None, part_update=None): path = self.img_path.get() ## Check if hist and canny hm have to be rerendered - if ( - not part_update - ): ## If partial update has not been forced, check if full update is required + if part_update == None: ## If partial update has not been forced, check if full update is required if self.img_current != self.img_old or self.img_size != self.img_size_old: part_update = False self.img_old = self.img_current @@ -324,7 +325,10 @@ class MainApp: else: part_update = True else: - print("Partial update forced!") + if part_update == True: + print("Partial update forced!") + else: + print("Full update forced!") if path != None and path != "": # Get all images at current path @@ -358,7 +362,7 @@ class MainApp: # Set grayscale img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) self.add_output(img_gray, "Grayscale") - + # Contrast / brightness boost contrast_val = contrast / 100 bright_val = bright / 100 @@ -425,6 +429,8 @@ class MainApp: # Write results to CSV file if not part_update: log.update() + else: + log.clear() # Prevent partial updates from breaking log # Show all data plt.show(block=False) ## Graphs