Skip to content

Commit

Permalink
Improve "Add Noise" node to support subtle noise generation (#3048) (#…
Browse files Browse the repository at this point in the history
…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.)
  • Loading branch information
Arcitec authored Jan 4, 2025
1 parent f230ce3 commit 204a567
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -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}")

0 comments on commit 204a567

Please sign in to comment.