diff --git a/graxpert/application/app.py b/graxpert/application/app.py index 23d9533..9e10b61 100644 --- a/graxpert/application/app.py +++ b/graxpert/application/app.py @@ -68,7 +68,6 @@ def initialize(self): eventbus.add_listener(AppEvents.CALCULATE_REQUEST, self.on_calculate_request) # denoising eventbus.add_listener(AppEvents.DENOISE_STRENGTH_CHANGED, self.on_denoise_strength_changed) - eventbus.add_listener(AppEvents.DENOISE_THRESHOLD_CHANGED, self.on_denoise_threshold_changed) eventbus.add_listener(AppEvents.DENOISE_REQUEST, self.on_denoise_request) # saving eventbus.add_listener(AppEvents.SAVE_AS_CHANGED, self.on_save_as_changed) @@ -329,9 +328,6 @@ def on_smoothing_changed(self, event): def on_denoise_strength_changed(self, event): self.prefs.denoise_strength = event["denoise_strength"] - def on_denoise_threshold_changed(self, event): - self.prefs.denoise_threshold = event["denoise_threshold"] - def on_denoise_request(self, event): if self.images.get("Original") is None: messagebox.showerror("Error", _("Please load your picture first.")) @@ -356,7 +352,6 @@ def on_denoise_request(self, event): ai_model_path, self.prefs.denoise_strength, batch_size=self.prefs.ai_batch_size, - threshold=self.prefs.denoise_threshold, progress=progress, ai_gpu_acceleration=self.prefs.ai_gpu_acceleration, ) diff --git a/graxpert/denoising.py b/graxpert/denoising.py index e6075ad..341eee6 100644 --- a/graxpert/denoising.py +++ b/graxpert/denoising.py @@ -11,7 +11,7 @@ from graxpert.ui.ui_events import UiEvents -def denoise(image, ai_path, strength, batch_size=4, window_size=256, stride=128, threshold=1.0, progress=None, ai_gpu_acceleration=True): +def denoise(image, ai_path, strength, batch_size=4, window_size=256, stride=128, progress=None, ai_gpu_acceleration=True): logging.info("Starting denoising") @@ -29,10 +29,15 @@ def denoise(image, ai_path, strength, batch_size=4, window_size=256, stride=128, median = np.median(image[::4, ::4, :], axis=[0, 1]) mad = np.median(np.abs(image[::4, ::4, :] - median), axis=[0, 1]) + + if "1.0.0" in ai_path or "1.1.0" in ai_path: + model_threshold = 1.0 + else: + model_threshold = 10.0 global cached_denoised_image if cached_denoised_image is not None: - return blend_images(input, cached_denoised_image, strength, threshold, median, mad) + return blend_images(input, cached_denoised_image, strength, model_threshold, median, mad) num_colors = image.shape[-1] if num_colors == 1: @@ -67,11 +72,6 @@ def denoise(image, ai_path, strength, batch_size=4, window_size=256, stride=128, logging.info(f"Available inference providers : {providers}") logging.info(f"Used inference providers : {session.get_providers()}") - if "1.0.0" in ai_path or "1.1.0" in ai_path: - model_threshold = 1.0 - else: - model_threshold = 10.0 - cancel_flag = False def cancel_listener(event): @@ -152,7 +152,7 @@ def cancel_listener(event): output = np.moveaxis(output, 0, -1) cached_denoised_image = output - output = blend_images(input, output, strength, threshold, median, mad) + output = blend_images(input, output, strength, model_threshold, median, mad) eventbus.remove_listener(AppEvents.CANCEL_PROCESSING, cancel_listener) logging.info("Finished denoising") diff --git a/graxpert/preferences.py b/graxpert/preferences.py index 5af1a59..94ba3e3 100644 --- a/graxpert/preferences.py +++ b/graxpert/preferences.py @@ -40,7 +40,6 @@ class Prefs: denoise_ai_version: AnyStr = None graxpert_version: AnyStr = graxpert_version denoise_strength: float = 0.5 - denoise_threshold: float = 10.0 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 7ea7098..9fe3035 100644 --- a/graxpert/ui/left_menu.py +++ b/graxpert/ui/left_menu.py @@ -225,10 +225,6 @@ def __init__(self, parent, **kwargs): self.denoise_strength.set(graxpert.prefs.denoise_strength) self.denoise_strength.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.DENOISE_STRENGTH_CHANGED, {"denoise_strength": self.denoise_strength.get()})) - self.denoise_threshold = tk.DoubleVar() - self.denoise_threshold.set(graxpert.prefs.denoise_threshold) - self.denoise_threshold.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.DENOISE_THRESHOLD_CHANGED, {"denoise_threshold": self.denoise_threshold.get()})) - self.create_children() self.setup_layout() self.place_children() @@ -252,11 +248,6 @@ def create_children(self): ) tooltip.Tooltip(self.denoise_strength_slider, text=tooltip.denoise_strength_text) - self.denoise_threshold_slider = ValueSlider( - self.sub_frame, width=default_label_width, variable_name=_("Denoise Threshold"), variable=self.denoise_threshold, min_value=0.1, max_value=10.0, precision=1 - ) - tooltip.Tooltip(self.denoise_threshold_slider, text=tooltip.denoise_threshold_text) - def setup_layout(self): super().setup_layout() @@ -264,7 +255,6 @@ def place_children(self): super().place_children() self.denoise_strength_slider.grid(column=1, row=0, pady=pady, sticky=tk.EW) - self.denoise_threshold_slider.grid(column=1, row=1, pady=pady, sticky=tk.EW) self.denoise_button.grid(column=1, row=2, pady=pady, sticky=tk.EW) def toggle(self):