用Skimage学习数字图像处理(021):图像特征提取之线检测(下)

本节是特征提取之线检测的下篇,讨论基于Hough变换的线检测方法。首先简要介绍Hough变换的基本原理,然后重点介绍Skimage中含有的基于Hough变换的直线和圆形检测到实现。

目录

10.4 Hough变换

10.4.1 原理

10.4.2 实现

10.4 Hough变换

Hough变换(霍夫变换)是一种在图像处理和计算机视觉中广泛使用的技术,是由Paul Hough在1962年提出。

Hough变换的一个主要优点是它对噪声和曲线间断的鲁棒性。它不仅限于检测直线,还可以用于检测圆、椭圆、三角形等多种形状。此外,Hough变换也广泛应用于计算机视觉的多个领域,如边缘检测、特征提取、模式识别等多个领域。

10.4.1 原理

Hough变换的基本原理是通过在参数空间中进行累加统计来检测图像中的基本形状,其核心思想是将图像空间中的曲线或直线变换到参数空间中,通过检测参数空间中的极值点来确定图像中曲线的描述参数,从而提取出规则的曲线。

有关原理的详细介绍,可参考相关的文献,再次不再赘述。我们重点介绍基于Skimage的Hough变换的实现。

10.4.2 实现

在Skimage中,提供了5个与Hough变换有关的函数,分别是:

  • skimage.transform.hough_line:进行直线Hough变换.
  • skimage.transform.hough_line_peaks:返回直线Hough变换的峰值.
  • skimage.transform.hough_circle:进行圆Hough变换
  • skimage.transform.hough_circle_peaks:返回圆形Hough变换的峰值.
  • skimage.transform.hough_ellipse:进行椭圆Hough变换.

(1)直线检测

使用skimage.transform.hough_line()和skimage.transform.hough_line_peaks()实现直线检测:

skimage.transform.hough_line(image, theta).
skimage.transform.hough_line_peaks(hspace, angles, dists, min_distance, min_angle, threshold, num_peaks)

部分参数说明

  • image:输入图像。
  • theta:Angles at which to compute the transform, in radians. Defaults to a vector of 180 angles evenly spaced in the range [-pi/2, pi/2).。
  • hspace:Hough transform accumulator。Angles at which the transform is computed, in radians.
  • angles:Angles at which the transform is computed, in radians。
  • dists:输入图像。
  • min_distance:输入图像。
  • min_angle:输入图像。
  • num_peaks:输入图像。
  • hspace:输入图像。

返回值

  • hspace:ndarray of uint64, shape (P, Q),Hough transform accumulator.
  • angles:Angles at which the transform is computed, in radians。

以下是官方提供的一个直线检测的实例:

import numpy as npfrom skimage.transform import hough_line, hough_line_peaks
from skimage.feature import canny
from skimage.draw import line as draw_line
from skimage import dataimport matplotlib.pyplot as plt
from matplotlib import cm# Constructing test image
image = np.zeros((200, 200))
idx = np.arange(25, 175)
image[idx, idx] = 255
image[draw_line(45, 25, 25, 175)] = 255
image[draw_line(25, 135, 175, 155)] = 255# Classic straight-line Hough transform
# Set a precision of 0.5 degree.
tested_angles = np.linspace(-np.pi / 2, np.pi / 2, 360, endpoint=False)
h, theta, d = hough_line(image, theta=tested_angles)# Generating figure 1
fig, axes = plt.subplots(1, 3, figsize=(15, 6))
ax = axes.ravel()ax[0].imshow(image, cmap=cm.gray)
ax[0].set_title('Input image')
ax[0].set_axis_off()angle_step = 0.5 * np.diff(theta).mean()
d_step = 0.5 * np.diff(d).mean()
bounds = [np.rad2deg(theta[0] - angle_step),np.rad2deg(theta[-1] + angle_step),d[-1] + d_step,d[0] - d_step,
]
ax[1].imshow(np.log(1 + h), extent=bounds, cmap=cm.gray, aspect=1 / 1.5)
ax[1].set_title('Hough transform')
ax[1].set_xlabel('Angles (degrees)')
ax[1].set_ylabel('Distance (pixels)')
ax[1].axis('image')ax[2].imshow(image, cmap=cm.gray)
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_axis_off()
ax[2].set_title('Detected lines')for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):(x0, y0) = dist * np.array([np.cos(angle), np.sin(angle)])ax[2].axline((x0, y0), slope=np.tan(angle + np.pi / 2))plt.tight_layout()
plt.show()

以下是处理结果示例:

(2)圆形检测

使用skimage.transform.hough_circle()和skimage.transform.hough_circle_peaks()检测圆形:

skimage.transform.hough_circle(image, radius, normalize, full_output)
skimage.transform.hough_circle_peaks(hspaces, radii, min_xdistance, min_ydistance, threshold, num_peaks, total_num_peaks, normalize)

以下是官方提供的一个圆形检测的实例:

import numpy as np
import matplotlib.pyplot as pltfrom skimage import data, color
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
from skimage.draw import circle_perimeter
from skimage.util import img_as_ubyte# Load picture and detect edges
image = img_as_ubyte(data.coins()[160:230, 70:270])
edges = canny(image, sigma=3, low_threshold=10, high_threshold=50)# Detect two radii
hough_radii = np.arange(20, 35, 2)
hough_res = hough_circle(edges, hough_radii)# Select the most prominent 3 circles
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii, total_num_peaks=3)# Draw them
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(10, 4))
image = color.gray2rgb(image)
for center_y, center_x, radius in zip(cy, cx, radii):circy, circx = circle_perimeter(center_y, center_x, radius, shape=image.shape)image[circy, circx] = (220, 20, 20)ax.imshow(image, cmap=plt.cm.gray)
plt.show()

以下是处理结果示例:

(3)椭圆检测

使用skimage.transform.hough_ellipse()检测椭圆形:

skimage.transform.hough_ellipse(image, threshold, accuracy, min_size, max_size)

以下是官方提供的一个椭圆检测的实例:

import matplotlib.pyplot as pltfrom skimage import data, color, img_as_ubyte
from skimage.feature import canny
from skimage.transform import hough_ellipse
from skimage.draw import ellipse_perimeter# Load picture, convert to grayscale and detect edges
image_rgb = data.coffee()[0:220, 160:420]
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, sigma=2.0, low_threshold=0.55, high_threshold=0.8)# Perform a Hough Transform
result = hough_ellipse(edges, accuracy=20, threshold=250, min_size=100, max_size=120)
result.sort(order='accumulator')# Estimated parameters for the ellipse
best = list(result[-1])
yc, xc, a, b = (int(round(x)) for x in best[1:5])
orientation = best[5]# Draw the ellipse on the original image
cy, cx = ellipse_perimeter(yc, xc, a, b, orientation)
image_rgb[cy, cx] = (0, 0, 255)
# Draw the edge (white) and the resulting ellipse (red)
edges = color.gray2rgb(img_as_ubyte(edges))
edges[cy, cx] = (250, 0, 0)fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, sharey=True
)ax1.set_title('Original picture')
ax1.imshow(image_rgb)ax2.set_title('Edge (white) and result (red)')
ax2.imshow(edges)plt.show()

以下是处理结果示例:

参考文献:

  1. Duda, R. O. and P. E. Hart, “Use of the Hough Transformation to Detect Lines and Curves in Pictures,” Comm. ACM, Vol. 15, pp. 11-15 (January, 1972)
  2. C. Galamhos, J. Matas and J. Kittler,”Progressive probabilistic Hough transform for line detection”, in IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 1999.

(未完待续)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/823515.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

项目实现:Boost搜索引擎

目录 一.项目背景 二. 搜索引擎的宏观原理 三.使用到的技术栈与项目环境 四.正排索引vs倒排索引 五.认识标签与去标签 六.建立索引模块 七,编写http服务端 八,编写前端页面 九.搜索结果的优化 遇到的问题: 项目源码:boos…

JS/TS笔记学习1

周末总得学点什么吧~ 奥利给! 跑火车 递归 减速 let currentIndex 0; let speed 500; // 初始速度,单位是毫秒 let decrement 20; // 每次迭代速度减少的量 const cells document.querySelectorAll(.cell); function highlightCell() { cells.forEach(…

Boost电感的作用

Boost电感在Boost升压电路中起着关键的作用。Boost电路是一种DC-DC电源转换器,其主要功能是将低电压直流(DC)信号转换为高电压直流(DC)信号。Boost电感在这个过程中起着平滑电流、储存能量和提高电路效率的作用。 具体…

柯桥商务口语之怎么样说英语更加礼貌?十个礼貌用语get起来!

当你在国外需要帮助的时候,这些礼貌用语真的是能够帮到你的哦 1.Would/Could you help me? 你可帮助我吗? 相信有些人想请求帮助的时候,一开口就用Can you,这个用在朋友或者熟人上面当然是没有问题的,但是如果是向…

Node.js 中的 RSA 加密、解密、签名与验证详解

引言 在现代的网络通信中,数据安全显得尤为重要。RSA加密算法因其非对称的特性,广泛应用于数据的加密、解密、签名和验证等安全领域。本文将详细介绍RSA算法的基本原理,并结合Node.js环境,展示如何使用内置的crypto模块和第三方库…

基于 LSTM 模型的古诗词自动生成算法实现及系统实现

近年来,研究者在利用循环神经网络(Recurrent Neural Network,RNN)进行古诗自动生成方面取得了显著的效果。但 RNN 存在梯度问题,导致处理时间跨度较长的序列时 RNN 并不具备长期记忆存储功能。随后,出现的基…

【架构方法论(一)】架构的定义与架构要解决的问题

文章目录 一. 架构定义与架构的作用1. 系统与子系统2. 模块与组件3. 框架与架构4. 重新定义架构:4R 架构 二、架构设计的真正目的-别掉入架构设计的误区1. 是为了解决软件复杂度2. 简单的复杂度分析案例 三. 案例思考 本文关键字 架构定义 架构与系统的关系从业务逻…

企业linux-堡垒机与跳板机测试案例-6140字详谈

在开始今天内容前,小编先把专栏前面学的Linux命令(部分)做了思维导图帮助各位平时的学习: 场景: 运维人员管理三台机器,通过远程连接工具连接上三台机器,也知道这三台机器root密码&#xff0c…

【Java探索之旅】掌握数组操作,轻松应对编程挑战

🎥 屿小夏 : 个人主页 🔥个人专栏 : Java编程秘籍 🌄 莫道桑榆晚,为霞尚满天! 文章目录 📑前言一、数组巩固练习1.1 数组转字符串1.2 数组拷贝1.3 求数组中的平均值1.4 查找数组中指…

Windows版Apache 2.4.59解压直用(免安装-绿色-项目打包直接使用)

windows下Apache分类 Apache分为 安装版和解压版 安装版: 安装方便,下一步------下一步就OK了,但重装系统更换环境又要重新来一遍,会特别麻烦 解压版(推荐): 这种方式(项目打包特别方便&#x…

力扣哈哈哈哈

public class MyStack {int top;Queue<Integer> q1;Queue<Integer> q2;public MyStack() {q1new LinkedList<Integer>();q2new LinkedList<Integer>();}public void push(int x) {q2.offer(x);//offer是入队方法while (!q1.isEmpty()){q2.offer(q1.pol…

HPTNet:为点云提取表面特征

论文题目&#xff1a;High-Performance Feature Extraction Network for Point Cloud Semantic Segmentation 论文地址&#xff1a;https://ieeexplore.ieee.org/abstract/document/10474110 文章目录 1. 平面几何特征的提取2. 几何和语义特征的分开处理3. Transformer模块4. 结…

MySQL基础知识——MySQL事务

事务背景 什么是事务&#xff1f; 一组由一个或多个数据库操作组成的操作组&#xff0c;能够原子的执行&#xff0c;且事务间相互独立&#xff1b; 简单来说&#xff0c;事务就是要保证一组数据库操作&#xff0c;要么全部成功&#xff0c;要么全部失败。 注&#xff1a;MyS…

代码随想录算法训练营第一天 | 704. 二分查找 | 27. 移除元素

704. 二分查找 int search(int* nums, int numsSize, int target) {int left 0, right numsSize, mid;while (left < right) {mid left (right -left) / 2;if (nums[mid] < target) {left mid 1;} else if (nums[mid] > target) {right mid;} else {return mid…

CMMI认证是什么?如何确定CMMI认证的目标和范围

CMMI&#xff08;Capability Maturity Model Integration&#xff09;认证是一种用于评估和改进组织软件和项目管理过程的框架。它由美国国防部软件工程所&#xff08;SEI&#xff09;开发&#xff0c;旨在帮助组织提高其软件和项目管理的成熟度水平。 CMMI认证的意义在于&…

哪里有su材质库免费下载?

su材质库是一套草图大师的通用材质大全&#xff0c;包含多种不同类型的材质包和材质贴图&#xff0c;使得设计师能够轻松在电脑上进行直观的构思。对于需要免费下载su材质库的用户&#xff0c;可以尝试通过以下途径获取。 1. 官方网站查找&#xff1a;许多软件都会在官网上提供…

第十六篇:springboot案例

文章目录 一、准备工作1.1 需求说明1.2 环境搭建1.3 开发规范1.4 思路 二、部门管理2.1 查询部门2.2 删除部门2.3 新增部门2.4 修改部门2.5 RequestMapping 三、员工管理3.1 分页查询3.2 删除员工3.3 新增员工3.3.1 新增员工3.3.2 文件上传 3.4 修改员工3.4.1 页面回显3.4.2 修…

【数据结构】-- 栈和队列

&#x1f308; 个人主页&#xff1a;白子寰 &#x1f525; 分类专栏&#xff1a;python从入门到精通&#xff0c;魔法指针&#xff0c;进阶C&#xff0c;C语言&#xff0c;C语言题集&#xff0c;C语言实现游戏&#x1f448; 希望得到您的订阅和支持~ &#x1f4a1; 坚持创作博文…

二十一.订单分析RFM模型

目录 1.数据读取 2.数据清洗 3.可视化分析 做图吧 4.RFM模型 本次数据条数为: 51101 import pandas as pd import numpy as np 1.数据读取 #读取文件 df_data pd.read_csv("../data/dataset.csv",encoding"gbk") df_data#因为列标签都是英文,这里我…

通讯录的实现(顺序表)

前言&#xff1a;上篇文章我们讲解的顺序表以及顺序表的具体实现过程&#xff0c;那么我们的顺序表在实际应用中又有什么作用呢&#xff1f;今天我们就基于顺序表来实现一下通讯录。 目录 一.准备工作 二.通讯录的实现 1.通讯录的初始化 2.插入联系人 3.删除联系人 4.…