def run_edges(image):
''' This function finds and colors all edges in the given image.
'''
# Convert image to gray
if len(image.shape) > 2:
grayimage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
else:
grayimage = image
# blur so the gradient operation is less noisy.
# uses a gaussian filter with sigma = 2
grayimage = gaussian_filter(grayimage, 2).astype(float)
# Filter with x and y sobel filters
dx = convolve2d(grayimage, sobel_filter_x())
dy = convolve2d(grayimage, sobel_filter_y())
# Convert to orientation and magnitude images
theta = transform_xy_theta(dx, dy)
mag = transform_xy_mag(dx, dy)
outimg = np.zeros((image.shape[0], image.shape[1], 3), dtype = np.uint8)
# Fill with corresponding color.
for r in range(outimg.shape[0]):
for c in range(outimg.shape[1]):
outimg[r,c,:] = get_color(theta[r,c], mag[r,c])
return outimg
评论列表
文章目录