Untitled
unknown
plain_text
a year ago
722 B
3
Indexable
Never
import scipy.signal as signal # Write a function that applies edge filter on a 2D matrix to return the outline of a mask def edge_filter_mask(image): # Define the Sobel filter sobel_x = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) sobel_y = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]) # Apply the filter on the image image_x = signal.convolve2d(image, sobel_x, mode='same', boundary='symm') image_y = signal.convolve2d(image, sobel_y, mode='same', boundary='symm') # Compute the magnitude magnitude = np.sqrt(np.square(image_x) + np.square(image_y)) # Compute the outline outline = np.zeros_like(magnitude) outline[magnitude > 0] = 1 return outline