imnoise
result = imnoise(img, type, [mean=0.0], [sigma=0.05], [density=0.05], [seed=])
Input: img, type, mean, sigma, density, seed · Output: result
What it is
img is an Image; type is a required string, "gaussian" or "salt_pepper". For "gaussian": mean/sigma are optional named numbers (defaults 0.0/0.05), the additive per-channel Gaussian noise's mean/standard-deviation in normalized [0,1] intensity units. For "salt_pepper": density is an optional named number (default 0.05), the fraction of pixels (not channel samples) flipped to pure black/white. seed is an optional named integer for reproducibility (same convention as randn/uniform); omitted, a fresh random seed is used. Adds synthetic noise for testing other CV algorithms.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = imnoise(img, type, [mean=0.0], [sigma=0.05], [density=0.05], [seed=]) | img Imageimg is an Image.type stringtype is a required string, "gaussian" or "salt_pepper".mean number, optional (default 0.0)For "gaussian": mean/sigma are optional named numbers (defaults 0.0/0.05), the additive per-channel Gaussian noise's mean/standard-deviation in normalized [0,1] intensity units.sigma number, optional (default 0.05)For "gaussian": mean/sigma are optional named numbers (defaults 0.0/0.05), the additive per-channel Gaussian noise's mean/standard-deviation in normalized [0,1] intensity units.density number, optional (default 0.05)For "salt_pepper": density is an optional named number (default 0.05), the fraction of pixels (not channel samples) flipped to pure black/white.seed optionalseed is an optional named integer for reproducibility (same convention as randn/uniform). | result Image | Returns a new Image, same dimensions as img. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
m = [80, 90, 85, 95; 88, 92, 84, 91; 86, 89, 93, 87; 90, 85, 88, 92]
img = image_from_matrix(m)
eq = histeq(img)
eq2 = imequalize(img) # same result, other name
imshow(eq)
noisy_g = imnoise(img, "gaussian", sigma=0.05, seed=1)
noisy_sp = imnoise(img, "salt_pepper", density=0.1, seed=2)
imshow(noisy_sp)
print(eq.width, eq2.width, noisy_g.width, noisy_sp.width)
4 4 4 4
from images
How it works
imnoise(img, type, [params...], [seed=]) — synthetic noise for testing other CV algorithms against. type="gaussian": mean=0.0, sigma=0.05 (normalized [0,1] intensity units), additive and independent per channel. type="salt_pepper": density=0.05, the fraction of PIXELS (not channel samples) flipped to pure black/white. seed= follows this codebase's shared stochastic-builtin convention (randn/uniform/kmeans_model/...) for reproducibility — see image::Image::add_gaussian_noise/add_salt_pepper_noise's doc comments for why the RNG itself is injected as a closure
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.