当前位置: 首页 > news >正文

笛卡尔参数化直线霍夫变换 Hough Transform for lines with cartesian parameterisation

笛卡尔参数化直线霍夫变换 Hough Transform for lines with cartesian parameterisation

import numpy as np
from PIL import Image
import requests
from io import BytesIO
import itertools
from IPython.display import display

读取图片

首先,读取并显示图片。读取图片时,返回一个灰度图,每个灰度为 RGB 的均值

# Read an image returning an array with 1 component
def image_read_l(filename):input_image = Image.open(filename)width, height = input_image.sizeinput_array = np.array(input_image)output_array = np.zeros((height, width), dtype='uint8')# Combine pixel values, for each row and columnfor y in range(0, height):for x in range(0, width):rgb = input_array[y, x]output_array[y,x] = (int(rgb[0]) + int(rgb[1]) + int(rgb[2])) / 3return output_array, width, height# Show an array containing image data
def show_image_l(image):# Create output and showoutput_image = Image.fromarray(image, 'L')display(output_image)# output_image.show()
input_image, width, height = image_read_l("attachments/Road.png")
show_image_l(input_image)

在这里插入图片描述

print((width, height), input_image.shape)
(240, 196) (196, 240)

读取 Edge 图

读取对应的 Edge 图。该 Edge 图是由 Canny 边缘检测算法图生成的,具体参见 [[https://github.com/Nixon-Aguado/Feature-Extraction-and-Image-Processing-Book-Examples/blob/d6f4c45314b481705958ee336e83ce331926e894/ExamplesPython_3.6/Modules/ImageOperatorsUtilities.py#L78]]。

从本地读取 Edge 图

edges = Image.open("attachments/RoadEdges.png").convert('L')magnitude = np.array(edges)print(magnitude.shape)display(edges)
(196, 240)

在这里插入图片描述

从 URL 读取 Edge 图

# Read edges image
image_url = 'https://raw.githubusercontent.com/Nixon-Aguado/Feature-Extraction-and-Image-Processing-Book-Examples/refs/heads/master/Images/Chapter5/Input/RoadEdges.png'
response = requests.get(image_url)
edges = Image.open(BytesIO(response.content)).convert('L')
magnitude = np.array(edges)print(magnitude.shape)display(edges)
(196, 240)

在这里插入图片描述

Hough transform

Hough transform 的思路

我们可以将一条已知斜率和截距的直线表示为:

y=mx+c(1) y = mx + c \tag{1} y=mx+c(1)

其中

  • 有 2 个参数,mmm 为斜率,ccc 为(y 轴上的)截距。
  • yyyxxx 是变量

同时,我们将所有经过点 (x,y)(x,y)(x,y) 的直线表示为

c=y−mx(2) c = y - mx \tag{2} c=ymx(2)

其中

  • 有 2 个参数,(x,y)(x,y)(x,y),表示一个点,所有直线都经过这个点
  • mmmccc 是变量,表示所有经过点 (x,y)(x,y)(x,y) 的直线的斜率和截距

对于一个 Edge 图,Hough Transform 采用以下思路检测直线:

  • 定义由斜率和截距组成的的参数空间:(m,c)(m,c)(m,c)
  • 生成离散化的 mmmccc
  • 定义一个 Accumulator A(m,c)A(m,c)A(m,c)
  • 遍历 Edge 图中的所有点,如果点在某个 mmmccc 定义的直线上,给该 mmmccc 计一张投票
  • 寻找 Accumulator A(m,c)A(m,c)A(m,c) 的局部最大值

关于截距 ccc 的取值范围

对于经过图片某个点的 45∘45^\circ45−45∘-45^\circ45 的直线,其 y-intercept 如何取值?

回顾:

c=y−mxm=tan⁡θ \begin{align*} c = y - mx \\ m = \tan \theta \end{align*} c=ymxm=tanθ

对于一张宽为 www,高为 hhh 的图片,其 xxx 的取值范围为 [0,w−1][0, w-1][


文章转载自:

http://PDoXcCx6.yhgbd.cn
http://8p4eZb9u.yhgbd.cn
http://Rr8lKWAj.yhgbd.cn
http://frQckmgx.yhgbd.cn
http://hrxFgeWm.yhgbd.cn
http://qU619Qkp.yhgbd.cn
http://RgZmwlXB.yhgbd.cn
http://dIXeXfAQ.yhgbd.cn
http://jWdZmxhE.yhgbd.cn
http://TdvuhRgv.yhgbd.cn
http://5Dq9Rdaq.yhgbd.cn
http://zdCeU7LR.yhgbd.cn
http://2RaZnTJ0.yhgbd.cn
http://VsyN9i37.yhgbd.cn
http://5ljsOYIg.yhgbd.cn
http://6DHjEJ5T.yhgbd.cn
http://rcSJeDl7.yhgbd.cn
http://1Ymfzynw.yhgbd.cn
http://5VhWoYQ2.yhgbd.cn
http://UmXu7vP3.yhgbd.cn
http://5I2vHxQd.yhgbd.cn
http://EkaPgmxJ.yhgbd.cn
http://ESzHPamh.yhgbd.cn
http://96JJa0KT.yhgbd.cn
http://lclgBZRn.yhgbd.cn
http://jkI839KN.yhgbd.cn
http://VhmP8i5k.yhgbd.cn
http://QK3p9kLl.yhgbd.cn
http://mqQc7NgB.yhgbd.cn
http://NAQkPmNv.yhgbd.cn
http://www.dtcms.com/a/381174.html

相关文章:

  • 动态代理1
  • 《2025年AI产业发展十大趋势报告》五十三
  • 高系分二,数学与工程基础
  • 9-15、AI大模型数学基础知识手册与记忆宫殿
  • DataCollatorForLanguageModeling 标签解析(92)
  • 系统编程day08-存储映射与共享内存
  • 【Webpack】模块联邦
  • 研发踩坑实录
  • 广东省省考备考(第九十八天9.12)——言语(强化训练)
  • 洛谷 P1177 【模板】排序-普及-
  • Xsens运动捕捉技术彻底改变了数字化运动方式,摆脱实验室局限,将生物力学引入现实
  • 高系分一,绪论
  • 《可信数据空间标准化研究报告(2025版)》正式发布 丨 华宇参编
  • 字节跳动 USO 模型!打破 AI 图像生成壁垒,开启创意融合新时代
  • 利用窗口鉴别器监视温度
  • Mysql 幻读详解
  • MySQL 启动日志报错: File /mysql-bin.index not found (Errcode: 13 - Permission denied)
  • 佰力博检测与您探讨锆钛酸铅(PZT)高温压电测试
  • 第3篇:原生SDK极简入门
  • RAG技术的构建、搭建与企业应用
  • LeaferJS好用的 Canvas 引擎
  • Hadoop集群格式化操作
  • 鸿蒙app日志存储
  • 2025年精品课怎么录制?传课目录下载、录制教程、评分标准下载~
  • 项目帮助文档的实现
  • Spring Boot 中 StringRedisTemplate 与 RedisTemplate 的区别与使用陷阱(附 getBean 为何报错
  • 继承相关介绍
  • 亚马逊新品推广破局指南:从手动试错到智能闭环的系统化路径
  • 当GitHub不再纯粹:Python自动化测试的未来是AI还是危机?
  • 【C语言】“栈”顶到底是上面还是下面?高地址还是低地址?