Exemplo n.º 1
0
def prewitt(img):
    filter_x = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
    filter_y = np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]])
    img_x = conv_img(img, filter_x)
    img_y = conv_img(img, filter_y)
    sq_img = np.sqrt(img_x**2 + img_y**2)
    img_out = np.floor(sq_img * (256 / np.max(sq_img)))
    return img_out
Exemplo n.º 2
0
def filter_gauss(img):
    gauss_filter = np.asarray([[0, 1, 2, 1, 0], [1, 3, 5, 3,
                                                 1], [2, 5, 9, 5, 2],
                               [1, 3, 5, 3, 1], [0, 1, 2, 1, 0]])
    gauss_filter = gauss_filter / np.sum(gauss_filter, axis=None)
    img_conv = conv_img(img, gauss_filter)
    return img_conv
Exemplo n.º 3
0
def LOG(img):
    filter_LOG = np.array([[-2, -4, -4, -4, -2], [-4, 0, 8, 0, -4],
                           [-8, 8, 24, 8, -4], [-4, 0, 8, 0, -4],
                           [-2, -4, -4, -4, -2]])
    img_conv = conv_img(img, filter_LOG)
    abs_img = np.abs(img_conv / np.sum(filter_LOG[filter_LOG > 0]))
    img_out = np.floor(abs_img).astype(int)
    return img_out
Exemplo n.º 4
0
def laplace(img, alpha=0.4):
    filter_laplace = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
    img_conv = conv_img(img, filter_laplace)
    # abs_img = np.abs(img_conv)
    img_nopad = img_conv / np.max(filter_laplace)
    img_pad = np.pad(img_nopad, [(1, 1), (1, 1)],
                     mode='constant')  # 2*pad = 2*1 = (h of filter - 1) = 3-1
    return regularize(alpha * img_pad + img)
Exemplo n.º 5
0
def filter_box(img):
    box_filter = np.ones((7, 7)) / (7 * 7)
    img_conv = conv_img(img, box_filter)
    return img_conv
Exemplo n.º 6
0
def filter_laplace(img):
    laplace_filter = (1.0 / 16) * np.array([[0, 0, -1, 0, 0], [
        0, -1, -2, -1, 0
    ], [-1, -2, 16, -2, -1], [0, -1, -2, -1, 0], [0, 0, -1, 0, 0]])
    img_conv = conv_img(img, laplace_filter)
    return img_conv