Compare commits

..

No commits in common. "509ffd24b18bf42f15e4f88eb44b2010093905a4" and "158b6bf2735fd4086dcba4dd2a8579a507fe3777" have entirely different histories.

3 changed files with 62 additions and 78 deletions

View File

@ -34,7 +34,7 @@
<property name="variable">int:canny_thr1</property> <property name="variable">int:canny_thr1</property>
<bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="padx">0</property> <property name="padx">0</property>
<property name="row">1</property> <property name="row">1</property>
</layout> </layout>
@ -44,7 +44,7 @@
<object class="ttk.Label" id="canny_thr1_label" named="True"> <object class="ttk.Label" id="canny_thr1_label" named="True">
<property name="text" translatable="yes">Canny thresh. 1</property> <property name="text" translatable="yes">Canny thresh. 1</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
</layout> </layout>
</object> </object>
@ -57,7 +57,7 @@
<property name="variable">int:canny_thr2</property> <property name="variable">int:canny_thr2</property>
<bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">3</property> <property name="column">2</property>
<property name="columnspan">1</property> <property name="columnspan">1</property>
<property name="row">1</property> <property name="row">1</property>
</layout> </layout>
@ -67,7 +67,7 @@
<object class="ttk.Label" id="canny_thr2_label" named="True"> <object class="ttk.Label" id="canny_thr2_label" named="True">
<property name="text" translatable="yes">Canny thresh. 2</property> <property name="text" translatable="yes">Canny thresh. 2</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">3</property> <property name="column">2</property>
<property name="columnspan">1</property> <property name="columnspan">1</property>
<property name="ipady">5</property> <property name="ipady">5</property>
<property name="row">0</property> <property name="row">0</property>
@ -84,9 +84,9 @@
<bind sequence="&lt;&lt;PathChooserPathChanged&gt;&gt;" handler="update" add="" /> <bind sequence="&lt;&lt;PathChooserPathChanged&gt;&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="columnspan">2</property> <property name="columnspan">1 </property>
<property name="ipadx">30</property> <property name="ipadx">30</property>
<property name="row">6</property> <property name="row">7</property>
<property name="rowspan">1</property> <property name="rowspan">1</property>
</layout> </layout>
</object> </object>
@ -100,7 +100,6 @@
<bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="columnspan">2</property>
<property name="ipadx">60</property> <property name="ipadx">60</property>
<property name="padx">0</property> <property name="padx">0</property>
<property name="row">3</property> <property name="row">3</property>
@ -112,7 +111,6 @@
<property name="text" translatable="yes">Contrast adjust</property> <property name="text" translatable="yes">Contrast adjust</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="columnspan">2</property>
<property name="row">2</property> <property name="row">2</property>
</layout> </layout>
</object> </object>
@ -125,7 +123,7 @@
<property name="variable">int:img_size</property> <property name="variable">int:img_size</property>
<bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="columnspan">2</property> <property name="columnspan">2</property>
<property name="ipadx">60</property> <property name="ipadx">60</property>
<property name="row">3</property> <property name="row">3</property>
@ -137,7 +135,7 @@
<object class="ttk.Label" id="img_size_label" named="True"> <object class="ttk.Label" id="img_size_label" named="True">
<property name="text" translatable="yes">Display size adjust</property> <property name="text" translatable="yes">Display size adjust</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="columnspan">2</property> <property name="columnspan">2</property>
<property name="row">2</property> <property name="row">2</property>
<property name="rowspan">1</property> <property name="rowspan">1</property>
@ -150,10 +148,10 @@
<property name="values">x y both</property> <property name="values">x y both</property>
<bind sequence="&lt;Leave&gt;" handler="update" add="" /> <bind sequence="&lt;Leave&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">1</property> <property name="column">0</property>
<property name="columnspan">1</property> <property name="columnspan">1</property>
<property name="row">4</property> <property name="ipadx">42</property>
<property name="rowspan">1</property> <property name="row">5</property>
</layout> </layout>
</object> </object>
</child> </child>
@ -173,9 +171,9 @@
<property name="text" translatable="yes">&lt; Prev img</property> <property name="text" translatable="yes">&lt; Prev img</property>
<bind sequence="&lt;ButtonPress&gt;" handler="img_prev" add="" /> <bind sequence="&lt;ButtonPress&gt;" handler="img_prev" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="ipadx">10</property> <property name="ipadx">10</property>
<property name="row">4</property> <property name="row">5</property>
<property name="rowspan">1</property> <property name="rowspan">1</property>
</layout> </layout>
</object> </object>
@ -185,9 +183,9 @@
<property name="text" translatable="yes">Next img &gt;</property> <property name="text" translatable="yes">Next img &gt;</property>
<bind sequence="&lt;ButtonPress&gt;" handler="img_next" add="" /> <bind sequence="&lt;ButtonPress&gt;" handler="img_next" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">3</property> <property name="column">2</property>
<property name="ipadx">10</property> <property name="ipadx">10</property>
<property name="row">4</property> <property name="row">5</property>
<property name="rowspan">1</property> <property name="rowspan">1</property>
</layout> </layout>
</object> </object>
@ -197,10 +195,10 @@
<property name="text" translatable="yes">Export PNG</property> <property name="text" translatable="yes">Export PNG</property>
<bind sequence="&lt;ButtonPress&gt;" handler="apply" add="" /> <bind sequence="&lt;ButtonPress&gt;" handler="apply" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">3</property> <property name="column">2</property>
<property name="columnspan">1</property> <property name="columnspan">1</property>
<property name="ipadx">10</property> <property name="ipadx">10</property>
<property name="row">6</property> <property name="row">7</property>
<property name="rowspan">1</property> <property name="rowspan">1</property>
</layout> </layout>
</object> </object>
@ -210,8 +208,8 @@
<property name="textvariable">int:export_id</property> <property name="textvariable">int:export_id</property>
<property name="width">15</property> <property name="width">15</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="row">6</property> <property name="row">7</property>
</layout> </layout>
</object> </object>
</child> </child>
@ -219,9 +217,9 @@
<object class="ttk.Label" id="label1"> <object class="ttk.Label" id="label1">
<property name="text" translatable="yes">Export Image by ID</property> <property name="text" translatable="yes">Export Image by ID</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="columnspan">2</property> <property name="columnspan">2</property>
<property name="row">5</property> <property name="row">6</property>
</layout> </layout>
</object> </object>
</child> </child>
@ -237,7 +235,7 @@
<property name="width">25</property> <property name="width">25</property>
<property name="wrap">word</property> <property name="wrap">word</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">4</property> <property name="column">3</property>
<property name="columnspan">1</property> <property name="columnspan">1</property>
<property name="row">0</property> <property name="row">0</property>
<property name="rowspan">8</property> <property name="rowspan">8</property>
@ -253,7 +251,6 @@
<bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="update" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="columnspan">2</property>
<property name="ipadx">60</property> <property name="ipadx">60</property>
<property name="row">1</property> <property name="row">1</property>
</layout> </layout>
@ -264,7 +261,6 @@
<property name="text" translatable="yes">Brightness adjust</property> <property name="text" translatable="yes">Brightness adjust</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="columnspan">2</property>
<property name="row">0</property> <property name="row">0</property>
</layout> </layout>
</object> </object>
@ -274,8 +270,17 @@
<property name="text" translatable="yes">Dataset path</property> <property name="text" translatable="yes">Dataset path</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">0</property> <property name="column">0</property>
<property name="row">6</property>
</layout>
</object>
</child>
<child>
<object class="ttk.Label" id="label4">
<property name="text" translatable="yes">Image control</property>
<layout manager="grid">
<property name="column">1</property>
<property name="columnspan">2</property> <property name="columnspan">2</property>
<property name="row">5</property> <property name="row">4</property>
</layout> </layout>
</object> </object>
</child> </child>
@ -284,10 +289,10 @@
<property name="text" translatable="yes">Export ID for entire dataset</property> <property name="text" translatable="yes">Export ID for entire dataset</property>
<bind sequence="&lt;ButtonRelease&gt;" handler="apply_all" add="" /> <bind sequence="&lt;ButtonRelease&gt;" handler="apply_all" add="" />
<layout manager="grid"> <layout manager="grid">
<property name="column">2</property> <property name="column">1</property>
<property name="columnspan">2</property> <property name="columnspan">2</property>
<property name="ipadx">30</property> <property name="ipadx">30</property>
<property name="row">7</property> <property name="row">8</property>
</layout> </layout>
</object> </object>
</child> </child>
@ -296,20 +301,7 @@
<property name="font">TkIconFont</property> <property name="font">TkIconFont</property>
<property name="text" translatable="yes">Powered by ARNweb.nl &amp; TomSelier.com</property> <property name="text" translatable="yes">Powered by ARNweb.nl &amp; TomSelier.com</property>
<layout manager="grid"> <layout manager="grid">
<property name="column">4</property> <property name="column">0</property>
<property name="columnspan">2</property>
<property name="row">8</property>
</layout>
</object>
</child>
<child>
<object class="ttk.Button" id="button1">
<property name="text" translatable="yes">Run analysis for entire dataset (!)</property>
<bind sequence="&lt;ButtonPress&gt;" handler="analyse_all" add="" />
<layout manager="grid">
<property name="column">2</property>
<property name="columnspan">2</property>
<property name="ipadx">15</property>
<property name="row">8</property> <property name="row">8</property>
</layout> </layout>
</object> </object>

View File

@ -37,9 +37,7 @@ class Logger:
self.file.write(self.csv(self.index)) self.file.write(self.csv(self.index))
self.file.write(self.csv(self.data)) self.file.write(self.csv(self.data))
self.clear()
def clear(self):
# Clear data # Clear data
self.index = [] self.index = []
self.data = [] self.data = []

View File

@ -2,7 +2,7 @@
import pathlib import pathlib
import pygubu import pygubu
import glob import glob
import tkinter from tkinter import *
from PIL import ImageTk, Image from PIL import ImageTk, Image
import numpy as np import numpy as np
import cv2 import cv2
@ -27,6 +27,7 @@ config_json = json.load(config_file)
log = Logger(config_json["out"]) log = Logger(config_json["out"])
## UI class setup ## UI class setup
class MainApp: class MainApp:
def __init__(self, master=None): def __init__(self, master=None):
@ -150,26 +151,26 @@ class MainApp:
else: else:
print("Nothing to export!") print("Nothing to export!")
def apply_all(self, event=None, export = True): def apply_all(self, event=None):
""" """
Export given preprocess id for every image in the dataset folder Export given preprocess id for every image in the dataset folder
""" """
img_id = self.export_id.get() img_id = self.export_id.get()
img_current = copy.deepcopy(self.img_current) img_current = copy.deepcopy(self.img_current)
if (export): now = datetime.datetime.now()
now = datetime.datetime.now() path = pathlib.Path(
path = pathlib.Path( config_json["out"],
config_json["out"], f"{self.output[1][img_id]}-all-{now.strftime('%Y-%m-%dT%H.%M.%S')}/",
f"{self.output[1][img_id]}-all-{now.strftime('%Y-%m-%dT%H.%M.%S')}/", )
) os.mkdir(path)
os.mkdir(path)
while True: while True:
self.img_next() self.img_next()
self.update(
if (export): part_update=True
self.apply(path=path) ) # Enforce partial update since we don't need the histograms etc.
self.apply(path=path)
if self.img_current == img_current: if self.img_current == img_current:
break break
@ -177,9 +178,6 @@ class MainApp:
## Ensure display is always correct with image ## Ensure display is always correct with image
self.update() self.update()
def analyse_all(self, event=None):
self.apply_all(export=False)
def add_output(self, data, name: str): def add_output(self, data, name: str):
""" """
Add CV2 image to canvas output Add CV2 image to canvas output
@ -198,9 +196,9 @@ class MainApp:
# Clear previously printed images # Clear previously printed images
self.tk_imgs = [] self.tk_imgs = []
self.meta.config(state=tkinter.NORMAL) self.meta.config(state=NORMAL)
self.meta.delete(1.0, tkinter.END) self.meta.delete(1.0, END)
self.meta.insert(tkinter.END, f"{self.img_name}\n") self.meta.insert(END, f"{self.img_name}\n")
# Draw all output images # Draw all output images
for idx, data in enumerate(self.output[0]): for idx, data in enumerate(self.output[0]):
@ -216,15 +214,15 @@ class MainApp:
self.canvas.configure(height=(drawY + size)) self.canvas.configure(height=(drawY + size))
self.canvas.create_image( self.canvas.create_image(
drawX, drawY, anchor=tkinter.NW, image=self.tk_imgs[idx], tags="og" drawX, drawY, anchor=NW, image=self.tk_imgs[idx], tags="og"
) )
drawX += size drawX += size
# Add name to text box # Add name to text box
self.meta.insert(tkinter.END, f"{idx}: {self.output[1][idx]}\n") self.meta.insert(END, f"{idx}: {self.output[1][idx]}\n")
# Clear output # Clear output
self.meta.config(state=tkinter.DISABLED) self.meta.config(state=DISABLED)
def createPlot(self, columns, rows): def createPlot(self, columns, rows):
fig, axs = plt.subplots(columns, rows) fig, axs = plt.subplots(columns, rows)
@ -286,8 +284,7 @@ class MainApp:
log.add("Canny Std", np.matrix(results).std()) log.add("Canny Std", np.matrix(results).std())
log.add("Canny Min", np.matrix(results).min()) log.add("Canny Min", np.matrix(results).min())
log.add("Canny Max", np.matrix(results).max()) log.add("Canny Max", np.matrix(results).max())
log.add("Canny Diff min", np.diff(func).min()) # log.add("Canny Diff max", np.diff(func))
log.add("Canny Diff max", np.diff(func).max())
def writeStats(self, img, labels, column, row): def writeStats(self, img, labels, column, row):
mean, std = imgStats(img) mean, std = imgStats(img)
@ -313,11 +310,13 @@ class MainApp:
log.add(f"Mean {label}", mean[idx]) log.add(f"Mean {label}", mean[idx])
log.add(f"Std {label}", std[idx]) log.add(f"Std {label}", std[idx])
def update(self, event=None, part_update=None): def update(self, event=None, part_update=False):
path = self.img_path.get() path = self.img_path.get()
## Check if hist and canny hm have to be rerendered ## Check if hist and canny hm have to be rerendered
if part_update == None: ## If partial update has not been forced, check if full update is required if (
not part_update
): ## 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: if self.img_current != self.img_old or self.img_size != self.img_size_old:
part_update = False part_update = False
self.img_old = self.img_current self.img_old = self.img_current
@ -325,10 +324,7 @@ class MainApp:
else: else:
part_update = True part_update = True
else: else:
if part_update == True: print("Partial update forced!")
print("Partial update forced!")
else:
print("Full update forced!")
if path != None and path != "": if path != None and path != "":
# Get all images at current path # Get all images at current path
@ -362,7 +358,7 @@ class MainApp:
# Set grayscale # Set grayscale
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
self.add_output(img_gray, "Grayscale") self.add_output(img_gray, "Grayscale")
# Contrast / brightness boost # Contrast / brightness boost
contrast_val = contrast / 100 contrast_val = contrast / 100
bright_val = bright / 100 bright_val = bright / 100
@ -429,8 +425,6 @@ class MainApp:
# Write results to CSV file # Write results to CSV file
if not part_update: if not part_update:
log.update() log.update()
else:
log.clear() # Prevent partial updates from breaking log
# Show all data # Show all data
plt.show(block=False) ## Graphs plt.show(block=False) ## Graphs