From 533a4f11db07285ba9211300b8d4fa5370a95299 Mon Sep 17 00:00:00 2001 From: Rikyf3 Date: Wed, 6 Nov 2024 10:38:11 +0100 Subject: [PATCH 1/7] Removed commented code --- graxpert/deconvolution.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/graxpert/deconvolution.py b/graxpert/deconvolution.py index 97290d9..3b9c771 100644 --- a/graxpert/deconvolution.py +++ b/graxpert/deconvolution.py @@ -2,7 +2,6 @@ import logging import numpy as np import onnxruntime as ort -import astropy.stats from graxpert.ai_model_handling import get_execution_providers_ordered from graxpert.application.app_events import AppEvents @@ -23,8 +22,6 @@ def deconvolve(image, ai_path, strength, psfsize, batch_size=4, window_size=512, logging.info(f"mapping batch_size of {batch_size} to {2 ** (batch_size).bit_length() // 2}") batch_size = 2 ** (batch_size).bit_length() // 2 # map batch_size to power of two - input = copy.deepcopy(image) - num_colors = image.shape[-1] H, W, _ = image.shape @@ -49,14 +46,6 @@ def deconvolve(image, ai_path, strength, psfsize, batch_size=4, window_size=512, output = copy.deepcopy(image) - # _min = np.min(image, axis=(0, 1)) - # image = image - _min + 1e-5 - # image = np.log(image) - - # _mean = np.mean(image, axis=(0, 1)) - # _std = np.std(image, axis=(0, 1)) - # image = (image - _mean) / _std * 0.1 - providers = get_execution_providers_ordered(ai_gpu_acceleration) session = ort.InferenceSession(ai_path, providers=providers) @@ -100,7 +89,6 @@ def cancel_listener(event): tile = tile - _min + 1e-5 tile = np.log(tile) - # _mean, _, _std = astropy.stats.sigma_clipped_stats(tile, sigma=2.0, axis=(0, 1)) _mean = tile.mean() _std = tile.std() _mean, _std = _mean.astype(np.float32), _std.astype(np.float32) @@ -161,8 +149,6 @@ def cancel_listener(event): output = output[offset: H + offset, offset: W + offset, :] output = np.clip(output, 0.0, 1.0) - # output = strength * output + (1 - strength) * input - eventbus.remove_listener(AppEvents.CANCEL_PROCESSING, cancel_listener) logging.info("Finished denoising") From d1fe0a7950670c34607b205de2d51d443de416ee Mon Sep 17 00:00:00 2001 From: Rikyf3 Date: Wed, 6 Nov 2024 10:44:29 +0100 Subject: [PATCH 2/7] Virtually reducing batch size of rgb images by 4 in deconvolution --- graxpert/deconvolution.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graxpert/deconvolution.py b/graxpert/deconvolution.py index 3b9c771..1fd3f60 100644 --- a/graxpert/deconvolution.py +++ b/graxpert/deconvolution.py @@ -22,6 +22,9 @@ def deconvolve(image, ai_path, strength, psfsize, batch_size=4, window_size=512, logging.info(f"mapping batch_size of {batch_size} to {2 ** (batch_size).bit_length() // 2}") batch_size = 2 ** (batch_size).bit_length() // 2 # map batch_size to power of two + if batch_size >= 4 and image.shape[-1] == 3: + batch_size = batch_size // 4 + num_colors = image.shape[-1] H, W, _ = image.shape From a8ef2ae39a07cd43238c293d0d45e8fd0f50a5d9 Mon Sep 17 00:00:00 2001 From: Rikyf3 Date: Wed, 6 Nov 2024 10:45:47 +0100 Subject: [PATCH 3/7] Fixed typos --- graxpert/deconvolution.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/graxpert/deconvolution.py b/graxpert/deconvolution.py index 1fd3f60..877761f 100644 --- a/graxpert/deconvolution.py +++ b/graxpert/deconvolution.py @@ -67,7 +67,7 @@ def cancel_listener(event): for b in range(0, ith * itw + batch_size, batch_size): if cancel_flag: - logging.info("Deconolution cancelled") + logging.info("Deconvolution cancelled") eventbus.remove_listener(AppEvents.CANCEL_PROCESSING, cancel_listener) return None @@ -108,7 +108,6 @@ def cancel_listener(event): input_tiles = np.array(input_tiles) input_tiles = np.moveaxis(input_tiles, -1, 1) input_tiles = np.reshape(input_tiles, [input_tiles.shape[0] * num_colors, 1, window_size, window_size]) - # input_tiles_with_strenght = np.concatenate([input_tiles, np.full_like(input_tiles, strength)], axis=1) output_tiles = [] sigma = np.full(shape=(input_tiles.shape[0], 1), fill_value=psfsize, dtype=np.float32) @@ -153,6 +152,6 @@ def cancel_listener(event): output = np.clip(output, 0.0, 1.0) eventbus.remove_listener(AppEvents.CANCEL_PROCESSING, cancel_listener) - logging.info("Finished denoising") + logging.info("Finished deconvolution") return output From 4c27f22832a7c47998024e1647bfd1e35c85db7e Mon Sep 17 00:00:00 2001 From: Rikyf3 Date: Thu, 7 Nov 2024 18:49:46 +0100 Subject: [PATCH 4/7] bugfix: blur psf slider not working properly --- graxpert/ui/left_menu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graxpert/ui/left_menu.py b/graxpert/ui/left_menu.py index 83dbb89..6bb7f77 100644 --- a/graxpert/ui/left_menu.py +++ b/graxpert/ui/left_menu.py @@ -232,8 +232,8 @@ def __init__(self, parent, **kwargs): self.deconvolution_strength.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.DECONVOLUTION_STRENGTH_CHANGED, {"deconvolution_strength": self.deconvolution_strength.get()})) self.deconvolution_psfsize = tk.DoubleVar() - self.deconvolution_strength.set(graxpert.prefs.deconvolution_psfsize) - self.deconvolution_strength.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.DECONVOLUTION_PSFSIZE_CHANGED, {"deconvolution_psfsize": self.deconvolution_psfsize.get()})) + self.deconvolution_psfsize.set(graxpert.prefs.deconvolution_psfsize) + self.deconvolution_psfsize.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.DECONVOLUTION_PSFSIZE_CHANGED, {"deconvolution_psfsize": self.deconvolution_psfsize.get()})) self.create_children() self.setup_layout() From 62f3c359b6f37dc392b80afe679b3501e4bbf05f Mon Sep 17 00:00:00 2001 From: Rikyf3 Date: Thu, 7 Nov 2024 19:01:19 +0100 Subject: [PATCH 5/7] Changed blur PSF size to FWHM in pixels, for more understandability --- graxpert/deconvolution.py | 3 +++ graxpert/preferences.py | 2 +- graxpert/ui/left_menu.py | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/graxpert/deconvolution.py b/graxpert/deconvolution.py index 877761f..bfb9d0b 100644 --- a/graxpert/deconvolution.py +++ b/graxpert/deconvolution.py @@ -11,6 +11,9 @@ def deconvolve(image, ai_path, strength, psfsize, batch_size=4, window_size=512, stride=448, progress=None, ai_gpu_acceleration=True): print("Starting deconvolution") strength = 0.95 * strength # TODO : strenght of exactly 1.0 brings no results, to fix + psfsize = np.clip((psfsize / 2.355 - 1.0) / 5.0, 0.05, 0.95) + + logging.info(f"Calculated normalized PSFsize value: {psfsize}") if batch_size < 1: logging.info(f"mapping batch_size of {batch_size} to 1") diff --git a/graxpert/preferences.py b/graxpert/preferences.py index 5430519..21e1db9 100644 --- a/graxpert/preferences.py +++ b/graxpert/preferences.py @@ -44,7 +44,7 @@ class Prefs: denoise_ai_version: AnyStr = None graxpert_version: AnyStr = graxpert_version deconvolution_strength: float = 0.5 - deconvolution_psfsize: float = 0.3 + deconvolution_psfsize: float = 5.0 denoise_strength: float = 0.5 ai_batch_size: int = 4 ai_gpu_acceleration: bool = True diff --git a/graxpert/ui/left_menu.py b/graxpert/ui/left_menu.py index 6bb7f77..14158e3 100644 --- a/graxpert/ui/left_menu.py +++ b/graxpert/ui/left_menu.py @@ -259,13 +259,13 @@ def create_children(self): self.tt_load = tooltip.Tooltip(self.deconvolution_button, text=tooltip.deconvolution_text) self.deconvolution_strength_slider = ValueSlider( - self.sub_frame, width=default_label_width, variable_name=_("Deconvolution Strength"), variable=self.deconvolution_strength, min_value=0.0, max_value=1.0, precision=2 + self.sub_frame, width=default_label_width, variable_name=_("Deconvolution Strength"), variable=self.deconvolution_strength, min_value=0.0, max_value=1.0, precision=1 ) tooltip.Tooltip(self.deconvolution_strength_slider, text=tooltip.deconvolution_strength_text) self.deconvolution_psfsize_slider = ValueSlider( - self.sub_frame, width=default_label_width, variable_name=_("Blur PSF Size"), - variable=self.deconvolution_psfsize, min_value=0.0, max_value=1.0, precision=2 + self.sub_frame, width=default_label_width, variable_name=_("Image FHWM (in pixels)"), + variable=self.deconvolution_psfsize, min_value=0.0, max_value=14.0, precision=1 ) tooltip.Tooltip(self.deconvolution_psfsize_slider, text=tooltip.deconvolution_psfsize_text) From 70172d137871e2c1bed7136db247dcc5732d6c4b Mon Sep 17 00:00:00 2001 From: David Schmelter Date: Sun, 10 Nov 2024 14:25:04 +0100 Subject: [PATCH 6/7] format code --- graxpert/deconvolution.py | 7 ++++--- graxpert/ui/left_menu.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/graxpert/deconvolution.py b/graxpert/deconvolution.py index f8e2e4a..db51a4e 100644 --- a/graxpert/deconvolution.py +++ b/graxpert/deconvolution.py @@ -1,5 +1,6 @@ import copy import logging + import numpy as np import onnxruntime as ort @@ -10,7 +11,7 @@ def deconvolve(image, ai_path, strength, psfsize, batch_size=4, window_size=512, stride=448, progress=None, ai_gpu_acceleration=True): print("Starting deconvolution") - strength = 0.95 * strength # TODO : strenght of exactly 1.0 brings no results, to fix + strength = 0.95 * strength # TODO : strenght of exactly 1.0 brings no results, to fix psfsize = np.clip((psfsize / 2.355 - 1.0) / 5.0, 0.05, 0.95) logging.info(f"Calculated normalized PSFsize value: {psfsize}") @@ -89,7 +90,7 @@ def cancel_listener(event): x = stride * i y = stride * j - tile = image[x: x + window_size, y: y + window_size, :] + tile = image[x : x + window_size, y : y + window_size, :] _min = np.min(tile, axis=(0, 1)) tile = tile - _min + 1e-5 @@ -151,7 +152,7 @@ def cancel_listener(event): logging.info(f"Progress: {p}%") last_progress = p - output = output[offset: H + offset, offset: W + offset, :] + output = output[offset : H + offset, offset : W + offset, :] output = np.clip(output, 0.0, 1.0) eventbus.remove_listener(AppEvents.CANCEL_PROCESSING, cancel_listener) diff --git a/graxpert/ui/left_menu.py b/graxpert/ui/left_menu.py index 904de18..b7a503a 100644 --- a/graxpert/ui/left_menu.py +++ b/graxpert/ui/left_menu.py @@ -264,8 +264,7 @@ def create_children(self): tooltip.Tooltip(self.deconvolution_strength_slider, text=tooltip.deconvolution_strength_text) self.deconvolution_psfsize_slider = ValueSlider( - self.sub_frame, width=default_label_width, variable_name=_("Image FHWM (in pixels)"), - variable=self.deconvolution_psfsize, min_value=0.0, max_value=14.0, precision=1 + self.sub_frame, width=default_label_width, variable_name=_("Image FHWM (in pixels)"), variable=self.deconvolution_psfsize, min_value=0.0, max_value=14.0, precision=1 ) tooltip.Tooltip(self.deconvolution_psfsize_slider, text=tooltip.deconvolution_psfsize_text) From 80c0339aa2835c89e22b956a8cf7b7c6a14a6303 Mon Sep 17 00:00:00 2001 From: David Schmelter Date: Sun, 10 Nov 2024 14:31:50 +0100 Subject: [PATCH 7/7] fix copy&paste typo in deconvolution cli --- graxpert/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graxpert/main.py b/graxpert/main.py index 799cc8a..26cf395 100644 --- a/graxpert/main.py +++ b/graxpert/main.py @@ -261,7 +261,7 @@ def main(): help='Number of image tiles which Graxpert will denoise in parallel. Be careful: increasing this value might result in out-of-memory errors. Valid Range: 1..32, default: "4"', ) - deconv_obj_parser = argparse.ArgumentParser("GraXpert Deconvolution Object", parents=[parser], description="GraXpert, the astronomical denoising tool") + deconv_obj_parser = argparse.ArgumentParser("GraXpert Deconvolution Object", parents=[parser], description="GraXpert, the astronomical deconvolution tool") deconv_obj_parser.add_argument( "-ai_version", "--ai_version",