Skip to content

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)

subtract(image, array)

Normalize the input image.

Parameters:

Name Type Description Default
image NDArray

[description]

required

Raises:

Type Description
ShapeMissmatchError

in case of ValueError due to numpy broadcasting failing

Returns:

Name Type Description
NDArray NDArray

[description]

Source code in src/artificial_artwork/image/image_operations.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def subtract(image: NDArray, array: NDArray) -> NDArray:
    """Normalize the input image.

    Args:
        image (NDArray): [description]

    Raises:
        ShapeMissmatchError: in case of ValueError due to numpy broadcasting failing

    Returns:
        NDArray: [description]
    """
    try:
        return image - array
    except ValueError as numpy_broadcast_error:
        raise ShapeMissmatchError(
            "Expected arrays with matching shapes."
        ) from numpy_broadcast_error