Skip to content

nst_image

noisy(image, ratio, seed=None)

Generates a noisy image by adding random noise to the content_image

Source code in src/artificial_artwork/image/image_operations.py
120
121
122
123
124
125
126
127
128
129
130
131
132
def noisy(
    image: NDArray,
    ratio: float,
    seed: int = None,
) -> NDArray:
    """Generates a noisy image by adding random noise to the content_image"""
    if ratio < 0 or 1 < ratio:
        raise InvalidRatioError("Expected a ratio value x such that 0 <= x <= 1")

    noise_image = np.random.uniform(-20, 20, image.shape).astype("float32")

    # Set the input_image to be a weighted average of the content_image and a noise_image
    return noise_image * ratio + image * (1 - ratio)