canny.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:computer-vision-algorithms 作者: aleju 项目源码 文件源码
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)"]
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号