From 204a5671a42f575879f29b09aaabaa8ae8399be8 Mon Sep 17 00:00:00 2001 From: Johnny Arcitec <38923130+Arcitec@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:16:19 +0100 Subject: [PATCH] Improve "Add Noise" node to support subtle noise generation (#3048) (#3055) Implements fine-grained control over the noise amount, by switching to a float-based noise multiplier instead. (The previous implementation was only able to generate noise in increments of +2.55 on the 0-255 pixel luminance scale.) --- .../image_filter/noise/add_noise.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/backend/src/packages/chaiNNer_standard/image_filter/noise/add_noise.py b/backend/src/packages/chaiNNer_standard/image_filter/noise/add_noise.py index f3c55a17f..2ee8d6f89 100644 --- a/backend/src/packages/chaiNNer_standard/image_filter/noise/add_noise.py +++ b/backend/src/packages/chaiNNer_standard/image_filter/noise/add_noise.py @@ -45,7 +45,15 @@ class NoiseType(Enum): NoiseColor.GRAY: "Monochrome", }, ), - SliderInput("Amount", min=0, max=100, default=50), + SliderInput( + "Amount", + min=0.0, + max=100.0, + default=50.0, + precision=1, + step=0.1, + slider_step=0.1, + ), seed_group(SeedInput()), ], outputs=[ @@ -67,18 +75,18 @@ def add_noise_node( img: np.ndarray, noise_type: NoiseType, noise_color: NoiseColor, - amount: int, + amount: float, seed: Seed, ) -> np.ndarray: if noise_type == NoiseType.GAUSSIAN: - return gaussian_noise(img, amount / 100, noise_color, seed.value) + return gaussian_noise(img, amount / 100.0, noise_color, seed.value) elif noise_type == NoiseType.UNIFORM: - return uniform_noise(img, amount / 100, noise_color, seed.value) + return uniform_noise(img, amount / 100.0, noise_color, seed.value) elif noise_type == NoiseType.SALT_AND_PEPPER: - return salt_and_pepper_noise(img, amount / 100, noise_color, seed.value) + return salt_and_pepper_noise(img, amount / 100.0, noise_color, seed.value) elif noise_type == NoiseType.POISSON: - return poisson_noise(img, amount / 100, noise_color, seed.value) + return poisson_noise(img, amount / 100.0, noise_color, seed.value) elif noise_type == NoiseType.SPECKLE: - return speckle_noise(img, amount / 100, noise_color, seed.value) + return speckle_noise(img, amount / 100.0, noise_color, seed.value) else: raise ValueError(f"Unknown noise type: {noise_type}")