From dcd4411fbdade4cd1a54596508341680c76b760c Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Wed, 27 Sep 2023 14:20:20 +0200 Subject: [PATCH] Added Export function Removed useless input :( --- src/config/config.template.json | 1 + src/helpers/gui/main.ui | 8 +++++--- src/suite.py | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/config/config.template.json b/src/config/config.template.json index 7594d9d..a17404f 100644 --- a/src/config/config.template.json +++ b/src/config/config.template.json @@ -1,4 +1,5 @@ { "path": "", + "out": "", "size": 750 } \ No newline at end of file diff --git a/src/helpers/gui/main.ui b/src/helpers/gui/main.ui index 6f882ea..6936046 100644 --- a/src/helpers/gui/main.ui +++ b/src/helpers/gui/main.ui @@ -192,7 +192,7 @@ - Useless button + Export PNG 2 @@ -215,7 +215,7 @@ - Useless imput + Export Image by ID 1 2 @@ -228,8 +228,10 @@ 15 0 4 + false disabled - Image metadata should appear here + true + Image IDs should appear here 25 word diff --git a/src/suite.py b/src/suite.py index 16988e4..2367bef 100644 --- a/src/suite.py +++ b/src/suite.py @@ -10,6 +10,8 @@ import time import matplotlib.pyplot as plt import json from helpers.statistics import imgStats +import datetime +import os ## UI config load PROJECT_PATH = pathlib.Path(__file__).parent @@ -97,11 +99,25 @@ class MainApp: ''' Export current dataset ''' + # Get export settings img_arr = self.tk_imgs img_id = self.export_id.get() + path = config_json["out"] - if (img_id >= 0 and img_id < len(img_arr)): - print("export") + if (img_id >= 0 and img_id < len(img_arr)): + # Create file + now = datetime.datetime.now() + new_file_name = F"{now.strftime('%Y-%m-%dT%H.%M.%S')}-id{img_id}.png" + + # Put data + file_path = pathlib.Path(path, new_file_name) + # print(file_path) + + imgpil = ImageTk.getimage(self.tk_imgs[img_id]) + imgpil.save(file_path, "PNG" ) + imgpil.close() + + print(f"Exported Image ID {img_id} to {os.path.join(path, new_file_name)}") else: print("Nothing to export!") @@ -206,6 +222,7 @@ class MainApp: def update(self, event=None): path = self.img_path.get() + # print(path) if path != None and path != "": # Get all images at current path