当前位置:网站首页>hough变换理解[通俗易懂]
hough变换理解[通俗易懂]
2022-07-25 18:43:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
hough变换概念 在计算机中,经常需要将一些特定的形状图形从图片中提取出来,如果直接用像素点来搜寻非常困难,这时候需要将图像从像素按照一定的算法映射到参数空间。hough变化提供了一种从图像像素信息到参数空间的变换方法。对于像直线,圆,椭圆这样的规则曲线hough是一种常用的算法。hough变化最大的优点在于特征边缘描述中间隔的容忍性并且该变换不受图像噪声的影响。
hough变换原理 hough变换是一种将图像上的点映射到累加的参数空间,实现对已知解析式曲线的识别。
参数空间 由于直线斜率k存在无穷大的情况,这里hough变换将原图像空间转换到极坐标系表示的参数空间。即直线 y = k ∗ x + b y=k*x+b y=k∗x+b转换到极坐标系空间 ρ = x c o s θ + y s i n θ \rho=xcos\theta+ysin\theta ρ=xcosθ+ysinθ, ρ \rho ρ表示直线到原点的距离, θ \theta θ限定了直线的斜率(这里只是说限定,没说是直线的斜率)。任意一条直线都可以通过 ( ρ , θ ) (\rho,\theta) (ρ,θ)来表示。参数空间 H ( ρ , θ ) H(\rho,\theta) H(ρ,θ)表示有限个点的集合。参数空间 H ( ρ , θ ) H(\rho,\theta) H(ρ,θ)每一个点都代表一条直线。 如图所示:
参数空间的累加投票 在进行hough变换前,先需要将图像的边缘图像提取出来,在边缘图像的基础上进行hough变换。经过边缘图像每一个点的直线有很多,如下图:
经过某一点的直线在参数空间的表示像一条正弦曲线。 在边缘图像中,只有表示边缘的像素点才有可能构成直线。现在回到参数空间,在参数空间 H ( ρ , θ ) H(\rho,\theta) H(ρ,θ)中,将经过边缘图像中每一个有效像素点(边缘像素点)的所有直线信息都加到 H ( ρ , θ ) H(\rho,\theta) H(ρ,θ)上。比如,像素点 ( x , y ) (x,y) (x,y)代表构成边缘的一个像素点,遍历 θ \theta θ,根据公式 ρ = x c o s θ + y s i n θ \rho=xcos\theta+ysin\theta ρ=xcosθ+ysinθ我们可以计算出所有经过点 ( x , y ) (x,y) (x,y)的直线信息。比如下图:
这儿三个点在一条直线上,不同颜色的线代表经过不通点的直线,图下面的表显示了直线的参数。将直线参数表示在参数空间的曲线上,如图所示:
每一条曲线都是由经过一个点的所有直线参数构成的。我们发现三条曲线在(60,81)附近交叉了,这表明 θ = 60 , ρ = 81 \theta=60,\rho=81 θ=60,ρ=81这条直线上有三个点。这就表明了我们如何从参数空间 H ( ρ , θ ) H(\rho,\theta) H(ρ,θ)上寻找直线信息。将 H H H看作为一个累加器,一个表示直线信息的累加器。设置某一阈值,超过阈值的参数点所代表的直线表明图像中存在这一直线。 hough变换示例
RGB= imread('lines.png');
imshow(RGB),title('original image');
I = rgb2gray(RGB);
BW = edge(I, 'canny'); % 用canny算法提取边缘图像
figure,imshow(BW),title('edge image');
[H, T, R]=hough(BW); % 计算得到的H为参数矩阵,T为限定直线的角度,R为直线到原点的值
figure, imshow(imadjust(mat2gray(H)), 'XData', T, ... % 绘制hough变换的图
'YData', R, 'InitialMagnification', 'fit'),title('hough image');
xlabel('\theta'), ylabel('\rho');
axis on; axis normal; hold on;
colormap(hot);
peaks = houghpeaks(H,4); % 该算法用来提取指定数目的峰值点,也是就是寻找直线
figure, imshow(BW);
hold on;
lines = houghlines(BW, T, R, peaks, 'FillGap',30, 'MinLength',30);
max_len = 0;
for k=1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',3,'Color','b');
plot(xy(1,1),xy(1,2),'x','LineWidth',3,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',3,'Color','red');
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end参考文献:《数字图像处理matlab版》-左飞 《数字图像处理第三版》 http://blog.csdn.net/poem_qianmo/article/details/26977557 https://en.wikipedia.org/wiki/Hough_transform http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127589.html原文链接:https://javaforall.cn
边栏推荐
- 【翻译】LFX 2022年春季导师资格开放--2月13日前申请CNCF项目!
- 银行理财子公司蓄力布局A股;现金管理类理财产品整改加速
- Introduction notes of JVM foundation and problem analysis
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
- Qtimgui 编译
- 分享六个实用的小程序插件
- 信达证券是国企吗?在信达证券开户资金安全吗?
- Detailed introduction and application of GaN (comprehensive and complete)
- MySQL index optimization introduction
- CircleIndicator组件,使指示器风格更加多样化
猜你喜欢

Circulaindicator component, which makes the indicator style more diversified

从目标检测到图像分割简要发展史

Vc/pe is running towards Qingdao

How to add EXE file to boot

Safe operation instructions for oscilloscope probe that must be read by engineers

What is hpapaas platform?

拍卖行作VC,第一次出手就投了个Web3

可视化模型网络连接

人人可参与开源活动正式上线,诚邀您来体验!

With a financing of 200million yuan, the former online bookstore is now closed nationwide, with only 3 stores left in 60 stores
随机推荐
ServletConfig class and ServletContext class
Tensor to img & imge to tensor (tensor conversion of pytorch)
3de 回复
曾拿2亿融资,昔日网红书店如今全国闭店,60家店仅剩3家
With a market value of 30billion yuan, the largest IPO in Europe in the past decade was re launched on the New York Stock Exchange
请问什么是国债逆回购?安全吗?
什么是hpaPaaS平台?
终极套娃 2.0 | 云原生交付的封装
How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
浏览器内核有几种,浏览器版本过低怎么升级
How high are the young people in this class for "ugly things"?
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
MySQL index optimization introduction
There was an error while marking a file for deletion
Software testing -- common testing tools
拍卖行作VC,第一次出手就投了个Web3
Care for front-line epidemic prevention workers, Haocheng JIAYE and Gaomidian sub district office jointly build the great wall of public welfare
[QNX Hypervisor 2.2用户手册]9.5 dump
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
What is the difference between GB and gib disk space units?