Esempio n. 1
0
def get_mask(image):
    """
    Get the polygon referent to the piece of image that we want to delete. And we convert it into
    a mask.
    :param image: Image where we want to delete something
    :return: mask with the piece of image that we want to delete
    """
    # Getting the area to delete from the image
    rdi = interactive.get_mouse_click(image)
    polygon = rdi.points
    # Getting the deleting mask
    return interactive.compute_mask(image.shape[1], image.shape[0], polygon)
Esempio n. 2
0
# Horizontal derivative approximations
sobel_x = [[-1, 0, 1],
           [-2, 0, 2],
           [-1, 0, 1]]

# Vertical derivative approximations
sobel_y = [[1, 2, 1],
           [0, 0, 0],
           [-1, -2, -1]]

# Loading image
image = np.array(Image.open('agbar.png'))

# Getting the area to delete from the image
rdi = interactive.get_mouse_click(image)
polygon = rdi.points

# Getting the deleting mask
mask = interactive.compute_mask(image.shape[1], image.shape[0], polygon)

# Image to grayscale
gray_image = np.mean(image, 2) / 255.

# Calculating the gradient image
gradient_image = np.sqrt(np.power(sg.convolve2d(gray_image, sobel_x, "same"), 2) +
                         np.power(sg.convolve2d(gray_image, sobel_y, "same"), 2))

# Adjusting the values gradient mask indexes to -100
gradient_image[mask == 1] = -100.