示例#1
0
def threshold_filter(a_img: ImageImpl, threshold: float) -> ImageImpl:
    """
    Given a matrix image representation, apply treshold transformation
    and return a binary matrix which follows this transformation:
    F(img[i,j]):| max_pixel_value if img[i, j] >= threshold
                | 0 else
    :param a_img: matrix image representation
    :param threshold: float between [0, max pixel value]
    :return: transformed matrix
    """

    # applies if element wise
    a_img.array = a_img.array >= threshold
    # transform a boolean matrix binary and scales
    a_img.array = a_img.array.astype(int) * MAX_PIXEL_VALUE

    return a_img
示例#2
0
def median_filter_fast(a_img: ImageImpl, kernel_size: int) -> ImageImpl:
    """
    Given an Image instance, apply the median filter using a square kernel of size
    kernel_size.
    :param a_img: Image instance
    :param kernel_size: kernel size int
    :return: transformed image
    """
    # build kernel
    kernel_size = int(kernel_size)

    filtered = ndimage.median_filter(a_img.array, size=kernel_size)
    a_img.array = filtered
    return a_img