def main():
"""Load image, apply Canny, plot."""
img = skiutil.img_as_float(data.camera())
img = filters.gaussian_filter(img, sigma=1.0)
sobel_y = np.array([
[-1, -2, -1],
[0, 0, 0],
[1, 2, 1]
])
sobel_x = np.rot90(sobel_y) # rotates counter-clockwise
img_sx = signal.correlate(img, sobel_x, mode="same")
img_sy = signal.correlate(img, sobel_y, mode="same")
g_magnitudes = np.sqrt(img_sx**2 + img_sy**2) / np.sqrt(2)
g_orientations = np.arctan2(img_sy, img_sx)
g_mag_nonmax = non_maximum_suppression(g_magnitudes, g_orientations)
canny = hysteresis(g_mag_nonmax, 0.35, 0.05)
ground_truth = feature.canny(data.camera())
util.plot_images_grayscale(
[img, g_magnitudes, g_mag_nonmax, canny, ground_truth],
["Image", "After Sobel", "After nonmax", "Canny", "Canny (Ground Truth)"]
)
评论列表
文章目录