Пример #1
0
def mean_filter_fast(a_img: ImageImpl, kernel_size: int) -> ImageImpl:
    """
    Given an Image instance, apply the mean filter using a square kernel of size
    kernel_size.
    :param a_img: Image instance
    :param kernel_size: kernel size int
    :return: transformed image
    """
    kernel_size = int(kernel_size)
    a_img.convolution_fast(
        np.ones((kernel_size, kernel_size)),
    )

    return a_img
Пример #2
0
def high_filter_fast(a_img: ImageImpl, kernel_size: int) -> ImageImpl:
    """
    Given a Image instance, apply high value filter.
    :param a_img:
    :param kernel_size:
    :return: transformed Image instance
    """
    kernel_size = int(kernel_size)
    kernel = np.ones((kernel_size, kernel_size)) * -1
    # augment the center value
    kernel[int(kernel_size / 2), int(kernel_size / 2)] = kernel_size

    a_img.convolution_fast(
        kernel,
    )
    return a_img
Пример #3
0
def gaussian_filter_fast(a_img: ImageImpl, kernel_size: int, sigma: float) -> ImageImpl:
    """
    Given an Image instance, apply the weighted gaussian filter using a square kernel of size
    kernel_size.
    :param a_img: Image instance
    :param kernel_size: kernel size int
    :param sigma: sigma value
    :return: transformed image
    """
    kernel_size = int(kernel_size)
    kernel = gaussian_kernel(kernel_size, sigma) * MAX_PIXEL_VALUE
    a_img.convolution_fast(
        (1 / kernel_size ** 2) * kernel,
    )

    return a_img