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

View File

@ -37,9 +37,7 @@ 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 = []

View File

@ -2,7 +2,7 @@
import pathlib
import pygubu
import glob
import tkinter
from tkinter import *
from PIL import ImageTk, Image
import numpy as np
import cv2
@ -27,6 +27,7 @@ config_json = json.load(config_file)
log = Logger(config_json["out"])
## UI class setup
class MainApp:
def __init__(self, master=None):
@ -150,26 +151,26 @@ class MainApp:
else:
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
"""
img_id = self.export_id.get()
img_current = copy.deepcopy(self.img_current)
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)
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()
if (export):
self.apply(path=path)
self.update(
part_update=True
) # Enforce partial update since we don't need the histograms etc.
self.apply(path=path)
if self.img_current == img_current:
break
@ -177,9 +178,6 @@ 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
@ -198,9 +196,9 @@ class MainApp:
# Clear previously printed images
self.tk_imgs = []
self.meta.config(state=tkinter.NORMAL)
self.meta.delete(1.0, tkinter.END)
self.meta.insert(tkinter.END, f"{self.img_name}\n")
self.meta.config(state=NORMAL)
self.meta.delete(1.0, END)
self.meta.insert(END, f"{self.img_name}\n")
# Draw all output images
for idx, data in enumerate(self.output[0]):
@ -216,15 +214,15 @@ class MainApp:
self.canvas.configure(height=(drawY + size))
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
# 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
self.meta.config(state=tkinter.DISABLED)
self.meta.config(state=DISABLED)
def createPlot(self, 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 Min", np.matrix(results).min())
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).max())
# log.add("Canny Diff max", np.diff(func))
def writeStats(self, img, labels, column, row):
mean, std = imgStats(img)
@ -313,11 +310,13 @@ class MainApp:
log.add(f"Mean {label}", mean[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()
## 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:
part_update = False
self.img_old = self.img_current
@ -325,10 +324,7 @@ class MainApp:
else:
part_update = True
else:
if part_update == True:
print("Partial update forced!")
else:
print("Full update forced!")
print("Partial update forced!")
if path != None and path != "":
# Get all images at current path
@ -429,8 +425,6 @@ 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