Added csv export entire dataset
This commit is contained in:
parent
a41d57f451
commit
7c1e14e1b4
@ -34,7 +34,7 @@
|
||||
<property name="variable">int:canny_thr1</property>
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="column">2</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">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -57,7 +57,7 @@
|
||||
<property name="variable">int:canny_thr2</property>
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">2</property>
|
||||
<property name="column">3</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">2</property>
|
||||
<property name="column">3</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="ipady">5</property>
|
||||
<property name="row">0</property>
|
||||
@ -84,9 +84,9 @@
|
||||
<bind sequence="<<PathChooserPathChanged>>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="columnspan">1 </property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">30</property>
|
||||
<property name="row">7</property>
|
||||
<property name="row">6</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -100,6 +100,7 @@
|
||||
<bind sequence="<ButtonRelease>" 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>
|
||||
@ -111,6 +112,7 @@
|
||||
<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>
|
||||
@ -123,7 +125,7 @@
|
||||
<property name="variable">int:img_size</property>
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="row">3</property>
|
||||
@ -135,7 +137,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">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="row">2</property>
|
||||
<property name="rowspan">1</property>
|
||||
@ -148,10 +150,10 @@
|
||||
<property name="values">x y both</property>
|
||||
<bind sequence="<Leave>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="column">1</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="ipadx">42</property>
|
||||
<property name="row">5</property>
|
||||
<property name="row">4</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
@ -171,9 +173,9 @@
|
||||
<property name="text" translatable="yes">< Prev img</property>
|
||||
<bind sequence="<ButtonPress>" handler="img_prev" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="ipadx">10</property>
|
||||
<property name="row">5</property>
|
||||
<property name="row">4</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -183,9 +185,9 @@
|
||||
<property name="text" translatable="yes">Next img ></property>
|
||||
<bind sequence="<ButtonPress>" handler="img_next" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">2</property>
|
||||
<property name="column">3</property>
|
||||
<property name="ipadx">10</property>
|
||||
<property name="row">5</property>
|
||||
<property name="row">4</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -195,10 +197,10 @@
|
||||
<property name="text" translatable="yes">Export PNG</property>
|
||||
<bind sequence="<ButtonPress>" handler="apply" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">2</property>
|
||||
<property name="column">3</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="ipadx">10</property>
|
||||
<property name="row">7</property>
|
||||
<property name="row">6</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -208,8 +210,8 @@
|
||||
<property name="textvariable">int:export_id</property>
|
||||
<property name="width">15</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="row">7</property>
|
||||
<property name="column">2</property>
|
||||
<property name="row">6</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
@ -217,9 +219,9 @@
|
||||
<object class="ttk.Label" id="label1">
|
||||
<property name="text" translatable="yes">Export Image by ID</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="row">6</property>
|
||||
<property name="row">5</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
@ -235,7 +237,7 @@
|
||||
<property name="width">25</property>
|
||||
<property name="wrap">word</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">3</property>
|
||||
<property name="column">4</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="row">0</property>
|
||||
<property name="rowspan">8</property>
|
||||
@ -251,6 +253,7 @@
|
||||
<bind sequence="<ButtonRelease>" 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>
|
||||
@ -261,6 +264,7 @@
|
||||
<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>
|
||||
@ -270,17 +274,8 @@
|
||||
<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">4</property>
|
||||
<property name="row">5</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
@ -289,10 +284,10 @@
|
||||
<property name="text" translatable="yes">Export ID for entire dataset</property>
|
||||
<bind sequence="<ButtonRelease>" handler="apply_all" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="column">2</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">30</property>
|
||||
<property name="row">8</property>
|
||||
<property name="row">7</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
@ -301,7 +296,20 @@
|
||||
<property name="font">TkIconFont</property>
|
||||
<property name="text" translatable="yes">Powered by ARNweb.nl & TomSelier.com</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<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="<ButtonPress>" 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>
|
||||
</layout>
|
||||
</object>
|
||||
|
@ -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 = []
|
||||
|
40
src/suite.py
40
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,13 +150,14 @@ 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)
|
||||
|
||||
if (export):
|
||||
now = datetime.datetime.now()
|
||||
path = pathlib.Path(
|
||||
config_json["out"],
|
||||
@ -167,9 +167,8 @@ class MainApp:
|
||||
|
||||
while True:
|
||||
self.img_next()
|
||||
self.update(
|
||||
part_update=True
|
||||
) # Enforce partial update since we don't need the histograms etc.
|
||||
|
||||
if (export):
|
||||
self.apply(path=path)
|
||||
|
||||
if self.img_current == img_current:
|
||||
@ -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:
|
||||
if part_update == True:
|
||||
print("Partial update forced!")
|
||||
else:
|
||||
print("Full update forced!")
|
||||
|
||||
if path != None and path != "":
|
||||
# Get all images at current path
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user