Skip to content

v1

apply_blur(image, blur_type, ksize=5)

Applies the specified blur to the image.

Parameters:

Name Type Description Default
image ndarray

Input image.

required
blur_type str

Type of blur ('average', 'gaussian', 'median', 'bilateral').

required
ksize int

Kernel size for the blur. Defaults to 5.

5

Returns:

Type Description
ndarray

np.ndarray: Blurred image.

Source code in inference/core/workflows/core_steps/classical_cv/image_blur/v1.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def apply_blur(image: np.ndarray, blur_type: str, ksize: int = 5) -> np.ndarray:
    """
    Applies the specified blur to the image.

    Args:
        image: Input image.
        blur_type (str): Type of blur ('average', 'gaussian', 'median', 'bilateral').
        ksize (int, optional): Kernel size for the blur. Defaults to 5.

    Returns:
        np.ndarray: Blurred image.
    """

    if blur_type == "average":
        blurred_image = cv2.blur(image, (ksize, ksize))
    elif blur_type == "gaussian":
        blurred_image = cv2.GaussianBlur(image, (ksize, ksize), 0)
    elif blur_type == "median":
        blurred_image = cv2.medianBlur(image, ksize)
    elif blur_type == "bilateral":
        blurred_image = cv2.bilateralFilter(image, ksize, 75, 75)
    else:
        raise ValueError(f"Unknown blur type: {blur_type}")

    return blurred_image