Skip to content

Commit

Permalink
Removed denoising threshold slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffenhir committed May 3, 2024
1 parent 3b9ebe6 commit e767742
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
5 changes: 0 additions & 5 deletions graxpert/application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."))
Expand All @@ -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,
)
Expand Down
16 changes: 8 additions & 8 deletions graxpert/denoising.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion graxpert/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions graxpert/ui/left_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -252,19 +248,13 @@ 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()

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):
Expand Down

0 comments on commit e767742

Please sign in to comment.