python边缘提取_Python-Anaconda练习candy算子用于边缘提取,再用hough变换检测直线边缘...

img: 待检测的图像。

threshold: 阈值,可先项,默认为10

line_length: 检测的最短线条长度,默认为50

line_gap: 线条间的最大间隙。增大这个值可以合并破碎的线条。默认为10

返回:

lines: 线条列表, 格式如((x0, y0), (x1, y0)),标明开始点和结束点。

下面,我们用canny算子提取边缘,然后检测哪些边缘是直线?

import skimage.transform as st

import matplotlib.pyplot as plt

from skimage import data,feature

#使用Probabilistic Hough Transform.

image = data.camera()

edges = feature.canny(image, sigma=2, low_threshold=1, high_threshold=25)

lines = st.probabilistic_hough_line(edges, threshold=10, line_length=5,line_gap=3)

# 创建显示窗口.

fig, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(16, 6))

plt.tight_layout()

#显示原图像

ax0.imshow(image, plt.cm.gray)

ax0.set_title(‘Input image‘)

ax0.set_axis_off()

#显示canny边缘

ax1.imshow(edges, plt.cm.gray)

ax1.set_title(‘Canny edges‘)

ax1.set_axis_off()

#用plot绘制出所有的直线

ax2.imshow(edges * 0)

for line in lines:

p0, p1 = line

ax2.plot((p0[0], p1[0]), (p0[1], p1[1]))

row2, col2 = image.shape

ax2.axis((0, col2, row2, 0))

ax2.set_title(‘Probabilistic Hough‘)

ax2.set_axis_off()

plt.show()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值