[go: up one dir, main page]

CN102819743B - Detection method for quickly identifying straight-line segments in digital image - Google Patents

Detection method for quickly identifying straight-line segments in digital image Download PDF

Info

Publication number
CN102819743B
CN102819743B CN201210289399.0A CN201210289399A CN102819743B CN 102819743 B CN102819743 B CN 102819743B CN 201210289399 A CN201210289399 A CN 201210289399A CN 102819743 B CN102819743 B CN 102819743B
Authority
CN
China
Prior art keywords
straight line
value
line segment
pixel
pixels
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201210289399.0A
Other languages
Chinese (zh)
Other versions
CN102819743A (en
Inventor
贾靓
闵革勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Qishuo Information Technology Co ltd
Original Assignee
Changzhou University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Changzhou University filed Critical Changzhou University
Priority to CN201210289399.0A priority Critical patent/CN102819743B/en
Publication of CN102819743A publication Critical patent/CN102819743A/en
Application granted granted Critical
Publication of CN102819743B publication Critical patent/CN102819743B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Image Analysis (AREA)

Abstract

本发明涉及对一种对图像内特定图形的定标方法,特别涉及一种快速识别数字图像中直线段的检测方法,包括以下步骤:a、输入具有单位像素宽的二值图像;b、设定待检测直线段的长度参数、变化参数、像素参数和范围参数;c、获得粗糙直线段;d、细分已检测到的直线段;e、链接临近的与当前直线段方向值之差小于差异阀值的直线段:方向值是对前景像素的临域相对于其中心位置的方向量化定义;差异阀值指方向值之差的阀值,用于判断两条直线段方向是否相同的量化标准;f、返回所找到的直线段。本发明的检测速度是优于目前已知的具有较好检测精度的TODIS;检测精度高于KHT和EDLines,并且本发明的精度不低于TOIDS。

The present invention relates to a method for calibrating a specific figure in an image, in particular to a detection method for quickly identifying a straight line segment in a digital image, comprising the following steps: a. inputting a binary image with a unit pixel width; b. setting Determine the length parameter, change parameter, pixel parameter and range parameter of the straight line segment to be detected; c, obtain the rough straight line segment; d, subdivide the detected straight line segment; e, the difference between the direction value of the adjacent link and the current straight line segment is less than Straight line segment of the difference threshold: the direction value is the quantitative definition of the direction of the neighborhood of the foreground pixel relative to its center position; the difference threshold refers to the threshold value of the difference between the direction values, which is used to determine whether the direction of two straight line segments is the same. Standard; f. Return the found straight line segment. The detection speed of the present invention is better than that of currently known TODIS with better detection accuracy; the detection accuracy is higher than that of KHT and EDLines, and the accuracy of the present invention is not lower than that of TOIDS.

Description

一种快速识别数字图像中直线段的检测方法A Detection Method for Rapid Recognition of Straight Lines in Digital Images

技术领域 technical field

本发明涉及对一种对图像内特定图形的定标方法,特别涉及一种快速识别数字图像中直线段的检测方法。The invention relates to a calibration method for a specific figure in an image, in particular to a detection method for quickly identifying a straight line segment in a digital image.

背景技术 Background technique

在计算机视觉和机器视觉学科中,直线段检测是一种能同时给出数字图像中直线长度和位置的直线检测方法。它的应用十分广泛,例如:图像压缩,材料缝隙检测,立体视觉,道路检测,机器人导航等。同时,它也是基于图论的目标识别方法中所使用到的一种基本的点特征。因此,线段检测不仅在工业生产中具有现实应用价值,而且也是构成更复杂算法的重要基础。In computer vision and machine vision disciplines, line segment detection is a line detection method that can simultaneously give the length and position of a line in a digital image. It has a wide range of applications, such as: image compression, material gap detection, stereo vision, road detection, robot navigation, etc. At the same time, it is also a basic point feature used in the target recognition method based on graph theory. Therefore, line segment detection not only has practical application value in industrial production, but also constitutes an important basis for more complex algorithms.

当前国内外主流的线段检测方法主要有三种:基于直线检测的线段检测、基于梯度信息的线段检测和基于边界跟踪的线段检测。At present, there are three mainstream line segment detection methods at home and abroad: line segment detection based on line detection, line segment detection based on gradient information, and line segment detection based on boundary tracking.

(1)基于直线检测的线段检测是在直线检测的基础上,在图像中对已被直线检测所识别的直线,根据其上的边界像素的分布,给出线段。这种方法的优点是可以直接使用现有成熟的直线检测算法。由于最早的直线检测方法问世于1962年,经过多年的发展,这种方法的种类和数量十分惊人,但大部分都基于霍夫变换,而霍夫变换的运算量非常巨大,由于量化误差的存在导致参数的不确定性和参数空间中的虚假峰值,其快速性较差。针对霍夫变换的上述问题,Xu等1990年提出了随机霍夫变换(randomized Hough transform,简称RHT)。随机霍夫变换采用多到一的映射,避免了标准霍夫变换(standard Hough transformm,简称SHT)一到多映射的庞大计算量,而且随机霍夫变换算法采用动态链表结构,只对多到一映射所得到的参数分配单元进行累积,降低了内存需求,同时使得随机霍夫变换具有参数空间无限大、参数精度任意高等特点。然而在处理复杂图像时,由于随机采样会引入大量的无效采样和累积,使方法的性能大为降低。虽然近年来直线检测有所创新,例如Fernandes于2008年提出的KHT算法(Gaussian Kernel-based Hough Transform;中文名:基于高斯核的霍夫变换,详见L.A.F.Fernandes,M.M.Oliveira,″Real-time line detection through an improved Houghtransform voting scheme″,Pattern Recognition,vol.41,no.1,pp.299-314.Jan.2008)和Mochizuki于2009年提出的N点随机霍夫算法(详见Y.Mochizuki,A.Torii,A.Imiya,″N-Point Hough transform for line detection″,Journal of Visual Communication and ImageRepresentation,vol.20,no.4,pp.242-253.May.2009)。通过深入分析发现,这些新方法虽然采用了新的霍夫变换形式,但这些新变换方法越来越依赖于前期预处理过程。比如KHT算法,虽然使用了统计学的二元高斯分布函数来产生直线峰值,但实际上这个统计函数的参数计算完全依赖于Pope于1994年和Lowe于1987年提出的链接与分割算法,KHT算法通过Pope和Lowe的算法获得了每条直线的样本空间,进而才能应用高斯函数。与KHT算法类似,N点随机霍夫算法由于使用随机组合的点来产生峰值,为了降低可能产生的组合总数,Mochizuki也使用了前期处理算法。这些预处理过程,实际上相当于简单的线段检测,因为它们为后续的霍夫变换提供了具有较好共线性的点集,而非传统的不具备几何意义的离散点。虽然新算法在直线检测上的精度与效率较以往有了提高,但这些算法在设计之初并没有考虑线段检测,所以需要额外添加一个后期处理过程,从检测到的直线中分割出线段。而且根据Akinlar于2011年的分析(详见C.Akinlar,C.Topal,″EDLines:Areal-time line segmentdetector with a false detection control″,Pattern Recognition Letters,vol.32,no.13,pp.1633-1642.Oct.2011),这些算法会融合不连续的线段,产生大量错误的检测结果,在较为复杂的图形图像检测中应用困难。所以,基于直线检测的线段检测很难完成快速处理任务,因而目前的线段检测算法较少采用这种方法。(1) The line segment detection based on the line detection is based on the line detection, and the line segment has been given in the image according to the distribution of the boundary pixels on the line that has been identified by the line detection. The advantage of this method is that it can directly use the existing mature line detection algorithm. Since the earliest line detection method came out in 1962, after years of development, the types and quantities of this method are amazing, but most of them are based on the Hough transform, and the calculation of the Hough transform is very large, due to the existence of quantization errors It leads to parameter uncertainty and spurious peaks in the parameter space, which is less fast. In response to the above problems of the Hough transform, Xu et al. proposed the randomized Hough transform (RHT for short) in 1990. The random Hough transform uses many-to-one mapping, which avoids the huge amount of calculation of the standard Hough transform (SHT) one-to-many mapping, and the random Hough transform algorithm uses a dynamic linked list structure, only for many-to-one The parameter allocation units obtained by mapping are accumulated, which reduces the memory requirement, and at the same time makes the random Hough transform have the characteristics of infinite parameter space and arbitrarily high parameter precision. However, when dealing with complex images, random sampling will introduce a large number of invalid sampling and accumulation, which greatly reduces the performance of the method. Although there have been innovations in line detection in recent years, for example, the KHT algorithm (Gaussian Kernel-based Hough Transform; Chinese name: Gaussian Kernel-based Hough Transform) proposed by Fernandes in 2008, see L.A.F.Fernandes, M.M.Oliveira, "Real-time line detection through an improved Houghtransform voting scheme", Pattern Recognition, vol.41, no.1, pp.299-314.Jan.2008) and the N-point random Hough algorithm proposed by Mochizuki in 2009 (see Y.Mochizuki for details, A.Torii, A.Imiya, "N-Point Hough transform for line detection", Journal of Visual Communication and Image Representation, vol.20, no.4, pp.242-253.May.2009). Through in-depth analysis, it is found that although these new methods adopt the new Hough transform form, these new transform methods are more and more dependent on the previous preprocessing process. For example, the KHT algorithm, although the statistical binary Gaussian distribution function is used to generate a straight line peak, but in fact the calculation of the parameters of this statistical function is completely dependent on the link and segmentation algorithm proposed by Pope in 1994 and Lowe in 1987, the KHT algorithm The sample space of each straight line is obtained through the algorithm of Pope and Lowe, and then the Gaussian function can be applied. Similar to the KHT algorithm, the N-point random Hough algorithm uses randomly combined points to generate peaks. In order to reduce the total number of possible combinations, Mochizuki also uses a pre-processing algorithm. These preprocessing processes are actually equivalent to simple line segment detection, because they provide a set of points with better collinearity for the subsequent Hough transform, rather than traditional discrete points that do not have geometric meaning. Although the accuracy and efficiency of the new algorithm for straight line detection have been improved compared to the past, these algorithms did not consider line segment detection at the beginning of the design, so an additional post-processing process needs to be added to segment the line segment from the detected straight line. And according to Akinlar's analysis in 2011 (see C.Akinlar, C.Topal, "EDLines: Areal-time line segment detector with a false detection control", Pattern Recognition Letters, vol.32, no.13, pp.1633- 1642.Oct.2011), these algorithms will fuse discontinuous line segments, resulting in a large number of wrong detection results, and it is difficult to apply in more complex graphic image detection. Therefore, line segment detection based on line detection is difficult to complete fast processing tasks, so the current line segment detection algorithm seldom uses this method.

(2)基于梯度信息的线段检测的基础原理是源于Burns于1986年提出的直线检测方法(J.B.Burns,A.R.Hanson,E.M.Riseman,″Extracting straight lines″,IEEE Trans.PatternAnal.Machine Intell.,vol.8,no.4,pp.425-455.1986),这种方法的关键思想是使用由二阶微分算子产生的边界像素的梯度方向来识别直线。几十年来,各种基于梯度信息的线段检测方法不断演化。在2008年,Gioi提出了一种免调节参数的快速线段检测算法LSD(ALineSegment Detector,中文名:一种直线段检测算法,详见G.v.Gioi,R.Jakubowicz,J.Morel,J.M.Randall,″LSD:A Line Segment detector with a false detection control″,CMLA.Centre deMathematiques et de leurs Applications,Ecole Normale Superieure de Cachan(ENS-CACHAN),Germany.2008)。LSD是在当时精度可以接受的,最快的线段检测方法。Yang在2011年提出了TODIS算法(A Line Segment Detector Using Two-orthogonal DirectionImage Scanning,中文名:基于双正交图像扫描的直线段检测算法,详见K.Yang,S.S.Ge,H.He,″Robust line detection using two-orthogonal direction image scanning″,Computer Visionand Image Understanding,vol.115,no.8,pp.1207-1222.Aug.2011),TODIS的精度超过了LSD,可以更准确地识别多个线段,但其速度仅为LSD的1/8。Akinlar在2011年提出的EDLines算法(A Real-time Line Segment Detector with a False Detection Control Based on EdgeDrawing Algorithm,中文名:一种基于边缘绘制算法的,错误检测可控的实时直线段检测算法)的速度接近LSD的10倍。EDLines的效率较以前的算法有大幅度提高,已经具备了快速检测的应用价值。通过分析EDLines,发现实现这种算法效率的关键是结合边缘检测和线段检测,即EDLines的输入并非离散点,而是经过预处理的具有一定几何信息的点集。这与KHT算法类似,不同的是EDLines的预处理采用了Topal于2010年提出的一种新的名为Edgedrawing的边缘检测算法(详见C.Topal,C.Akinlar,Y.Genc,″Edge drawing:a heuristic approach torobust real-time edge detection″,ICPR,to be published)。由于输入的是链接的边界,EDLines只要对其进行分割或融合,加上验证就可以完成线段检测。(2) The basic principle of line segment detection based on gradient information is derived from the straight line detection method proposed by Burns in 1986 (J.B.Burns, A.R.Hanson, E.M.Riseman, "Extracting straight lines", IEEE Trans.PatternAnal.Machine Intell., vol .8, no.4, pp.425-455.1986), the key idea of this method is to use the gradient direction of the boundary pixels produced by the second-order differential operator to identify the straight line. Over the decades, various gradient-based line segment detection methods have evolved. In 2008, Gioi proposed a fast line segment detection algorithm LSD (ALineSegment Detector, Chinese name: a line segment detection algorithm without adjusting parameters, see G.v.Gioi, R.Jakubowicz, J.Morel, J.M.Randall, "LSD : A Line Segment detector with a false detection control", CMLA.Centre de Mathematiques et de leurs Applications, Ecole Normale Superieure de Cachan (ENS-CACHAN), Germany.2008). LSD is the fastest line segment detection method with acceptable accuracy at that time. In 2011, Yang proposed the TODIS algorithm (A Line Segment Detector Using Two-orthogonal DirectionImage Scanning, Chinese name: A Line Segment Detection Algorithm Based on Dual Orthogonal Image Scanning, see K.Yang, S.S.Ge, H.He, "Robust line detection using two-orthogonal direction image scanning", Computer Vision and Image Understanding, vol.115, no.8, pp.1207-1222.Aug.2011), the accuracy of TODIS exceeds that of LSD, and it can more accurately identify multiple line segments , but its speed is only 1/8 of that of LSD. The speed of the EDLines algorithm proposed by Akinlar in 2011 (A Real-time Line Segment Detector with a False Detection Control Based on EdgeDrawing Algorithm, Chinese name: a real-time line segment detection algorithm based on edge drawing algorithm, error detection and controllable) Close to 10 times of LSD. Compared with the previous algorithms, the efficiency of EDLines has been greatly improved, and it already has the application value of rapid detection. By analyzing EDLines, it is found that the key to achieve the efficiency of this algorithm is to combine edge detection and line segment detection, that is, the input of EDLines is not discrete points, but preprocessed point sets with certain geometric information. This is similar to the KHT algorithm, except that the preprocessing of EDLines uses a new edge detection algorithm named Edgedrawing proposed by Topal in 2010 (see C.Topal, C.Akinlar, Y.Genc, "Edge drawing : a heuristic approach torobust real-time edge detection", ICPR, to be published). Since the input is the boundary of the link, EDLines only needs to divide or fuse it and add verification to complete line segment detection.

但是,通过分析发现,EDLines检测方法存在以下几个关键问题。However, through analysis, it is found that the EDLines detection method has the following key problems.

第一,对于特定环境中的特定线段检测,该方法的免参数调节特性实质上是一种缺陷。在不同的应用中,对所要检测的线段和检测中受到的干扰是不同的。在一种特定环境中,要到达一个比较理想的检测效果,需要在该环境中按检测要求,进行大量实验,确定针对该环境及其目标的参数才能完成。免参数调节是一种普适性质,与实际应用的最优化方法是相悖的。First, for specific line segment detection in specific environments, the parameter-tuning-free nature of the method is essentially a drawback. In different applications, the line segment to be detected and the interference received in the detection are different. In a specific environment, in order to achieve a relatively ideal detection effect, it is necessary to conduct a large number of experiments in accordance with the detection requirements in this environment, and determine the parameters for the environment and its goals. Free parameter adjustment is a universal property, which is contrary to the practical optimization method.

第二,线段检测采用了门限为1像素的最小二乘法,固定的门限降低了检测精度。由于其免参数性质,1像素的门限不能改变,这直接导致了该算法只能检测曲率变化几乎为0的理想直线,从其实际的检测结果看,具有小幅变化非零曲率的线段往往被分割为多个小线段。如果被检测线段要求一定的长度,这种分割特性会大幅降低检测精度。Second, the least squares method with a threshold of 1 pixel is used for line segment detection, and the fixed threshold reduces the detection accuracy. Due to its parameter-free nature, the threshold of 1 pixel cannot be changed, which directly leads to the fact that the algorithm can only detect ideal straight lines with almost zero curvature changes. From its actual detection results, line segments with small changes in non-zero curvature are often segmented for multiple small line segments. If the detected line segment requires a certain length, this segmentation feature will greatly reduce the detection accuracy.

第三,该算法的验证过程依赖梯度方向,而且跳过对长线段的验证。实际上,由于输入为Edge drawing按梯度方向产生的点集,而验证过程仍然使用梯度方向作为依据,降低了验证意义。而且采用仅验证短线段,对长线段不做验证的策略,虽然减少了计算量,但降低了验证效果。因此,该算法的精度与LSD相比,并没有很大改善。Third, the verification process of the algorithm depends on the gradient direction and skips the verification of long line segments. In fact, since the input is the point set generated by Edge drawing according to the gradient direction, the verification process still uses the gradient direction as the basis, which reduces the significance of verification. Moreover, the strategy of only verifying short line segments and not verifying long line segments reduces the amount of calculation, but reduces the verification effect. Therefore, the accuracy of this algorithm does not improve much compared to LSD.

(3)基于边界跟踪的线段检测的概念最早由Etemadi在1992年提出(A.Etemadi,″Robustsegmentation ofedge data″,Conf.on Image Processing and its Applications,USA,1992,pp.311-314),这种方法使用由边缘检测产生的边界点信息,通过沿着边界点组成的边界移动,将相邻的边界点链接为曲线,再根据一定的准则对曲线进行分割,从而得到线段。Etemadi的算法的优点是简单快速,缺点是线段检测精度较低,在结果图像中残留有较多的仅有5、6像素长的短线段。这些年,Etemadi算法虽然较多地应用在各种视觉任务中,但一直没有多少改进,仍停留在上世纪90年代的水平。(3) The concept of line segment detection based on boundary tracking was first proposed by Etemadi in 1992 (A. Etemadi, "Robustsegmentation of edge data", Conf. on Image Processing and its Applications, USA, 1992, pp.311-314), which The first method uses the boundary point information generated by edge detection to link adjacent boundary points into a curve by moving along the boundary composed of boundary points, and then divides the curve according to certain criteria to obtain line segments. The advantage of Etemadi's algorithm is that it is simple and fast, but the disadvantage is that the accuracy of line segment detection is low, and there are many short line segments with a length of only 5 or 6 pixels remaining in the resulting image. In recent years, although the Etemadi algorithm has been widely used in various visual tasks, it has not been improved much, and it still remains at the level of the 1990s.

目前线段检测的发展趋势基本上是围绕梯度信息展开的,虽然精度和效率较以往有了较大提高,但由于近年的算法过于依赖梯度信息,忽视了边界本身的几何信息,以及缺乏有效的预处理和后处理手段,因而线段检测的创新和改进余地还是很大的。而工程应用仍迫切需要线段检测方法的速度和精度有较大的提高。At present, the development trend of line segment detection basically revolves around the gradient information. Although the accuracy and efficiency have been greatly improved compared with the past, the algorithms in recent years rely too much on the gradient information, ignore the geometric information of the boundary itself, and lack effective prediction. Processing and post-processing means, so there is still a lot of room for innovation and improvement in line segment detection. However, engineering applications still urgently need to improve the speed and accuracy of line segment detection methods.

发明内容 Contents of the invention

本发明要解决的技术问题是:为了克服现有技术中的不足,本发明提供一种快速识别数字图像中直线段的检测方法,这种方法采用了与以往国内外惯用的基于霍夫变换理论方法的不同理论,结合了数字图像中像素的梯度信息及几何特征,应用统计学方法,能够快速准确地检测图像中具有给定几何特征值的直线段。通过分析和比较近年来国际上流行的线段检测方法和这种方法的计算复杂度,其识别速度和准确性在一定程度上达到,甚至超过了目前已知的国际同类方法,从而具备了较好的工业应用价值和学术理论价值。The technical problem to be solved by the present invention is: in order to overcome the deficiencies in the prior art, the present invention provides a detection method for quickly identifying straight line segments in digital images. The different theories of the method combine the gradient information and geometric features of pixels in digital images, and apply statistical methods to quickly and accurately detect straight line segments with given geometric feature values in images. By analyzing and comparing the internationally popular line segment detection method in recent years and the computational complexity of this method, its recognition speed and accuracy have reached to a certain extent, even surpassed the currently known international similar methods, thus having a better Industrial application value and academic theoretical value.

(1)由于目前国际主流直线段检测方法普遍采用了无参数化设计,降低了人工干预程度,这种设计在某些方面具有一定优势,但在工业生产实际应用中,由于实际要求千差万别,无参数化的设计仅根据其预设的内部逻辑进行检测,会产生大量无用信息,无法满足工业级应用对检测速度和准确性的要求。本发明通过要求人工输入或设定四个参数,即线段长度、线段曲率变化程度、试探性链接像素数和线段融合范围,根据外界要求和实施条件,自动改变算法内部逻辑和计算量,较之无参数化设计,在对所要检测的直线段具有特定要求的工业应用中,能以适宜的速度给出准确的结果。(1) Since the current international mainstream straight line segment detection methods generally adopt non-parametric design, which reduces the degree of manual intervention, this design has certain advantages in some aspects, but in the actual application of industrial production, due to the wide variety of actual requirements, there is no The parametric design only detects according to its preset internal logic, which will generate a lot of useless information, which cannot meet the detection speed and accuracy requirements of industrial applications. The present invention automatically changes the internal logic and calculation amount of the algorithm according to external requirements and implementation conditions by requiring manual input or setting of four parameters, that is, the length of the line segment, the degree of curvature change of the line segment, the number of tentative link pixels and the fusion range of the line segment. Without parametric design, it can give accurate results at an appropriate speed in industrial applications that have specific requirements for the straight line segment to be detected.

(2)根据所使用理论分类,目前常用的直线段检测方法大致包括基于霍夫变换原理、梯度信息和几何信息三类。由于霍夫变换计算量过大,采用该原理的方法效率低下,精度一般,近年比较有代表性的是2008年诞生的KHT方法。梯度信息方法在速度上有较大突破,但精度上仍与传统的霍夫变换方法区别不大,近来的典型方法为2011年出现的EDLines方法。几何信息方法常年来没有大的突破,依然停留在上世纪90年代的水平,典型的如1992年诞生的Etemadi方法。本发明结合了梯度信息和几何特征两种方法,规避了EDLines方法使用单一梯度信息并集成固化的前期边界检测方法的设计思路,通过分离前期边界检测和后期线段检测,使得本发明可以模块化地与任何边界检测方法搭配,完成检测任务,并且本发明并不依赖单一的梯度信息,而是根据给定几何参数,有针对性地开展检测任务,在检测过程中使用统计学方法对检测结果进行实时修定。通过效果对比和计算复杂性分析,本发明的速度明显高于KHT方法和Etemadi方法,略低于EDLines方法;其准确度明显高于KHT方法和Etemadi方法,高于EDLines方法。(2) According to the theoretical classification used, the currently commonly used straight line segment detection methods roughly include three categories based on the Hough transform principle, gradient information and geometric information. Due to the large amount of calculation of the Hough transform, the method using this principle is inefficient and the accuracy is average. In recent years, the KHT method born in 2008 is more representative. The gradient information method has a great breakthrough in speed, but the accuracy is still not much different from the traditional Hough transform method. The recent typical method is the EDLines method that appeared in 2011. The geometric information method has not made a big breakthrough all the year round, and still stays at the level of the 1990s, a typical example is the Etemadi method born in 1992. The present invention combines two methods of gradient information and geometric features, and avoids the design idea of using single gradient information and integrating solidified early boundary detection methods in the EDLines method. By separating the early boundary detection and the late line segment detection, the present invention can be modularized It can be matched with any boundary detection method to complete the detection task, and the present invention does not rely on a single gradient information, but carries out the detection task in a targeted manner according to the given geometric parameters, and uses statistical methods to analyze the detection results during the detection process. Revised in real time. Through effect comparison and calculation complexity analysis, the speed of the present invention is obviously higher than the KHT method and the Etemadi method, slightly lower than the EDLines method; its accuracy is obviously higher than the KHT method and the Etemadi method, and higher than the EDLines method.

本发明解决其技术问题所采用的技术方案是:一种快速识别数字图像中直线段的检测方法,包括以下步骤:The technical solution adopted by the present invention to solve the technical problem is: a detection method for quickly identifying straight line segments in a digital image, comprising the following steps:

(a)输入具有单位像素宽的二值图像,所述的二值图像由前景像素和背景像素两种像素组成,前景像素指包含某些图形信息的像素点,背景像素指不包含图形信息的像素点:由边缘检测提供二值图像,再使用骨骼化方法得到具有单位像素宽的二值图像;(a) Input a binary image with a unit pixel width. The binary image is composed of foreground pixels and background pixels. Foreground pixels refer to pixels containing certain graphic information, and background pixels refer to pixels that do not contain graphic information. Pixels: A binary image is provided by edge detection, and then a binary image with a unit pixel width is obtained by using the skeletalization method;

(b)设定待检测直线段的长度参数、变化参数、像素参数和范围参数:长度参数指最终检测结果中可接受直线段的最小长度;变化参数指对直线段曲率变化程度的容忍度,容忍度越大,则所检测到的直线段越接近曲线段,即直线段由几段方向具有明显差异的子线段组成;像素参数指直线段局部曲率发生明显变化时,试探性链接的像素数目;范围参数指线段融合范围参数;(b) Set the length parameter, change parameter, pixel parameter and range parameter of the straight line segment to be detected: the length parameter refers to the minimum length of the straight line segment acceptable in the final detection result; the change parameter refers to the tolerance to the degree of curvature change of the straight line segment, The greater the tolerance, the closer the detected straight line segment is to the curve segment, that is, the straight line segment is composed of several sub-line segments with obvious differences in direction; the pixel parameter refers to the number of pixels that are tentatively linked when the local curvature of the straight line segment changes significantly ;The range parameter refers to the line segment fusion range parameter;

(c)获得粗糙直线段;(c) Obtain a rough straight line segment;

(d)细分已检测到的直线段;(d) Subdividing the detected straight line segments;

(e)链接临近的与当前直线段的方向值之差小于差异阀值的直线段:所述的方向值是对前景像素的临域相对于其中心位置的方向量化定义;所述的差异阀值指方向值之差的阀值,用于判断两条直线段方向是否相同的量化标准;(e) Link the adjacent straight line segment whose direction value difference with the current straight line segment is less than the difference threshold: the direction value is a quantitative definition of the direction of the neighborhood of the foreground pixel relative to its center position; the difference threshold Value refers to the threshold value of the difference between the direction values, which is used to determine whether the directions of two straight line segments are the same;

(f)返回所找到的直线段。(f) Return the line segment found.

所述的步骤(c)的具体步骤为The specific steps of the step (c) are

(c1)定义方向值、方向值之差和差异阀值;(c1) Define the direction value, the difference between the direction values and the difference threshold;

(c2)按一定顺序对步骤(a)中输入的二值图像进行扫描,根据当前的图像扫描顺序确定特定方向值,所述的特定方向值指与代表扫描方向的方向值的差不超过差异阀值的所有指向未扫描区域的方向值;(c2) Scan the binary image input in step (a) in a certain order, and determine a specific direction value according to the current image scanning sequence, and the specific direction value means that the difference from the direction value representing the scanning direction does not exceed the difference Threshold values for all directions pointing to unscanned areas;

(c3)当发现前景像素时,暂停扫描,以前景像素为中心,只检测步骤(c2)中所述的特定方向值所指向的临域,如果发现前景像素,则继续检测步骤(c2)中所述的特定方向值指向的临域,重复这一过程,直至临域内未发现前景像素或抵达图像边界为止;(c3) When a foreground pixel is found, pause the scan, center on the foreground pixel, and only detect the neighborhood pointed to by the specific direction value described in step (c2), if a foreground pixel is found, continue to detect in step (c2) The neighborhood pointed to by the specific direction value, repeating this process until no foreground pixel is found in the neighborhood or reaches the image boundary;

(c4)试探性链接:确定起始方向值,所述的起始方向值是除去步骤(c2)中所述的特定方向值后,与扫描方向临近但指向未扫描区域的方向,所述的临近是指在图像空间中2个像素之间没有间隔其它像素;以步骤(c3)中发现的最后一个前景像素为起点,检查起始方向值所指向的临域是否具有前景像素;若发现新前景像素,则设置旧前景像素为背景像素,记录其方向值并试探性链接新前景像素;重复该过程直至所链接的前景像素总数等于像素参数,或在总数未达到像素参数前未发现新前景像素;(c4) Tentative link: Determine the starting direction value, the starting direction value is the direction close to the scanning direction but pointing to the unscanned area after removing the specific direction value described in step (c2), the described Proximity means that there is no interval between two pixels in the image space; starting from the last foreground pixel found in step (c3), check whether the neighborhood pointed to by the starting direction value has a foreground pixel; if a new Foreground pixels, set the old foreground pixels as background pixels, record their orientation values and tentatively link new foreground pixels; repeat this process until the total number of linked foreground pixels is equal to the pixel parameter, or no new foreground is found before the total number does not reach the pixel parameter pixel;

(c5)在试探性链接过程中,建立一个临时数据结构和一个用于永久保存的永久数据结构,所述的永久数据结构包括临时区域和永久区域,记录每个方向值的像素数并动态获取在当前时刻的最大方向值,所述的方向值的像素数指取该方向值的前景像素个数,所述的最大方向值指具有最多前景像素个数的方向值:所有在试探性链接过程中产生的每个方向值的像素数被记录在一个初始化后的临时数据结构中;(c5) During the tentative linking process, establish a temporary data structure and a permanent data structure for permanent storage, the permanent data structure includes a temporary area and a permanent area, record the number of pixels of each direction value and obtain it dynamically The maximum direction value at the current moment, the number of pixels of the direction value refers to the number of foreground pixels that take the direction value, and the maximum direction value refers to the direction value with the largest number of foreground pixels: all during the tentative linking process The number of pixels of each direction value generated in is recorded in an initialized temporary data structure;

在每次试探性连接中,若已链接的前景像素的个数未达到像素参数且当前像素周围没有发现新前景像素,则检查在试探性链接过程中所链接的前景像素的个数是否超过长度参数,若超过,则记录已链接的所有像素,并将它们标识为一条直线段,若未超过,则丢弃这些像素;In each tentative connection, if the number of linked foreground pixels does not reach the pixel parameter and no new foreground pixels are found around the current pixel, check whether the number of linked foreground pixels exceeds the length during the tentative linking process parameter, if it exceeds, record all the pixels that have been linked and identify them as a straight line segment, if not, discard these pixels;

若已链接的前景像素的个数达到像素参数且当前像素周围仍存在新前景像素,则将当前像素的方向值和上一次试探性链接的方向值记录在永久数据结构的临时区域中,并开始根据待链接前景像素的方向值与最大方向值的差,判断是否继续链接;If the number of linked foreground pixels reaches the pixel parameter and there are still new foreground pixels around the current pixel, record the direction value of the current pixel and the direction value of the last tentative link in the temporary area of the permanent data structure, and start According to the difference between the direction value of the foreground pixel to be linked and the maximum direction value, it is judged whether to continue the link;

(c6)如果最大方向值和待链接前景像素的方向值之差小于差异阀值,则链接该像素并在永久数据结构的临时区域中记录其方向值,否则在当前像素位置再次启动试探性链接;(c6) If the difference between the maximum orientation value and the orientation value of the foreground pixel to be linked is less than the difference threshold, then link the pixel and record its orientation value in the temporary area of the permanent data structure, otherwise start the tentative link again at the current pixel position ;

(c7)在试探性链接结束时,计算临时数据结构中的最大方向值和永久数据结构临时区域中的最大方向值之差:(c7) At the end of the heuristic linking, compute the difference between the maximum orientation value in the temporary data structure and the maximum orientation value in the temporary area of the permanent data structure:

如果差值小于差异阀值,则将临时数据结构中由试探性链接保存的前景像素和对应的方向值保存在永久数据结构的临时区域中,重复步骤(c6),直至未发现新前景像素、抵达图像边界为止;然后再根据长度参数判断是否将永久数据结构临时区域中的前景像素保存至永久区域并重新初始化临时数据结构;If the difference is less than the difference threshold, the foreground pixels and corresponding direction values saved by the tentative link in the temporary data structure are stored in the temporary area of the permanent data structure, and step (c6) is repeated until no new foreground pixels, Until the image boundary is reached; then judge whether to save the foreground pixels in the temporary area of the permanent data structure to the permanent area and re-initialize the temporary data structure according to the length parameter;

如果差值大于差异阀值,则中止链接,根据长度参数判断是否将永久数据结构临时区域中的前景像素保存至永久区域并重新初始化临时数据结构。If the difference is greater than the difference threshold, stop the link, judge whether to save the foreground pixels in the temporary area of the permanent data structure to the permanent area and reinitialize the temporary data structure according to the length parameter.

前景像素和背景像素分别定义为具有非0值像素和0值像素,或者分别定义为值为255的像素和值小于255的像素。Foreground and background pixels are defined as pixels with non-zero value and 0 value, or as pixels with value 255 and pixels with value less than 255, respectively.

所述的步骤(c2)中,图像扫描顺序按从上至下,从左至右进行。In the step (c2), the image scanning sequence is performed from top to bottom and from left to right.

所述的步骤(c1)中方向值的定义由滤波窗口和方向度量单位产生,完成方向值和方向值之差的定义后,再定义差异阀值。The definition of the direction value in the step (c1) is generated by the filtering window and the direction measurement unit. After the definition of the direction value and the difference between the direction values is completed, the difference threshold is defined.

所述的步骤(c1)中,将数字图像中所使用的二维滤波函数的离散值的个数及其分布形状作为滤波窗口,滤波窗口大小为3×3,方向值可以由整数值定义,也可以是角度值或弧度值。定义方向值后,就可以量化不同方向之间的差异,即根据差异准则来计算方向值之差,所述的差异准则是指两条直线方向偏差在差异阀值以内,即视作具有相同方向的直线,例如,计算两个方向之间较小或较大的夹角,取其中之一为方向值之差。In the step (c1), the number of discrete values of the two-dimensional filter function used in the digital image and its distribution shape are used as the filter window, the size of the filter window is 3×3, and the direction value can be defined by an integer value, Can also be an angle or radian value. After defining the direction value, the difference between different directions can be quantified, that is, the difference between the direction values is calculated according to the difference criterion. The difference criterion means that the direction deviation of two straight lines is within the difference threshold, that is, they are regarded as having the same direction , for example, calculates the smaller or larger angle between two directions, and takes one of them as the difference between the direction values.

一般地,当方向值为角度值或弧度值时,相应的差异阀值可以是45°或即当两条直线的方向值之差小于45°或时,这两条直线段被视为具有相同的方向。Generally, when the direction value is an angle value or a radian value, the corresponding difference threshold can be 45° or That is, when the difference between the direction values of two straight lines is less than 45° or When , the two straight line segments are considered to have the same direction.

方向值由整数值定义,定义如下:设x轴正方向的方向值为0,按逆时针方向,每隔45°的方向值依次为1、2、3、4、5、6、7;方向值之差由下式给出:The direction value is defined by an integer value, which is defined as follows: Let the direction value of the positive direction of the x-axis be 0, and in the counterclockwise direction, the direction values at every 45° are 1, 2, 3, 4, 5, 6, 7; direction The difference in values is given by:

if|dir1-dir2|>4then difference=8-|dir1-dir2|;else difference=|dir1-dir2|.if|dir1-dir2|>4then difference=8-|dir1-dir2|; else difference=|dir1-dir2|.

其中dir1和dir2分别表示两条直线段的方向值,difference代表dir1和dir2的差值;差异阀值定义为2。即当两条直线段的方向值之差小于2时,这两条直线段被视为具有相同方向值的直线段。Where dir1 and dir2 represent the direction values of the two straight line segments respectively, and difference represents the difference between dir1 and dir2; the difference threshold is defined as 2. That is, when the difference between the direction values of two straight line segments is less than 2, the two straight line segments are regarded as straight line segments with the same direction value.

所述的步骤(c2)中,特定方向值为6、7和0。In the step (c2), the specific direction values are 6, 7 and 0.

通过在计算机上运行基于Visual Studio开发且采用了本发明步骤(c)方法的实验程序,对大量图像进行处理并通过调查由步骤(c)生成的永久数据结构永久区域中每条直线段的方向值信息,发现小幅变化曲率的理想直线段的方向值信息普遍具有高斯分布特征,即仅有一个明显峰值且该峰值是最大方向值;而曲线段则具有至少两个以上的峰值。By running the experimental program based on Visual Studio development and adopting the step (c) method of the present invention on the computer, a large number of images are processed and by investigating the direction of each straight line segment in the permanent data structure permanent area generated by the step (c) It is found that the direction value information of the ideal straight line segment with small curvature changes generally has the characteristics of Gaussian distribution, that is, there is only one obvious peak and the peak is the maximum direction value; while the curve segment has at least two peaks.

根据这一发现,存储于永久数据结构永久区域中的每条直线段所对应的方向值信息都会被检测,当其最大方向值和次大方向值的比超过人工输入的变化参数时,既认为该线段是曲线段并开始分割。因此,所述的步骤(d)的具体步骤为According to this discovery, the direction value information corresponding to each straight line segment stored in the permanent area of the permanent data structure will be detected. The line segment is the curve segment and starts splitting. Therefore, the specific steps of the step (d) are

(d1)检测存储于永久数据结构永久区域中的每条直线段所对应的方向值信息,当直线段的最大方向值和次大方向值之比超过变化参数时,则该直线段为曲线段并进行分割;(d1) Detect the direction value information corresponding to each straight line segment stored in the permanent area of the permanent data structure. When the ratio of the largest direction value to the second largest direction value of the straight line segment exceeds the change parameter, the straight line segment is a curve segment and to divide;

(d2)对于步骤(d1)中发现的曲线段,从其任意端点开始,逐一检查每个像素的方向值并在初始化后的临时数据结构中记录方向值,如果该方向值与临时数据结构中已记录的任意方向值之差大于差异阀值,则标记这个像素为潜在分割点并初始化临时数据结构;重复上述步骤,直至曲线段上的所有点都被检测过;(d2) For the curve segment found in step (d1), starting from any of its endpoints, check the direction value of each pixel one by one and record the direction value in the initialized temporary data structure, if the direction value is the same as that in the temporary data structure If the difference between the recorded arbitrary direction values is greater than the difference threshold, mark this pixel as a potential segmentation point and initialize the temporary data structure; repeat the above steps until all points on the curve segment have been detected;

(d3)计算每两个潜在分割点之间的距离,如果距离不小于长度参数,则将该曲线段在这两个潜在分割点进行分割。(d3) Calculate the distance between every two potential split points, and if the distance is not less than the length parameter, split the curve segment at these two potential split points.

通过步骤(c)和步骤(d)的检测与分割,图像中可能存在方向值差异小于差异阀值,且端点间距离小于长度参数的直线段,当前子程序会试图融合多条具有这些特征的直线段,使之形成单一直线段。步骤(e)的最大难点是如何按当前直线段的大体走向来探索其附近的直线段。通过在计算机上运行基于Visual Studio开发且采用了本发明步骤(c)和步骤(d)方法的实验程序,对大量图像进行处理并通过调查运行结果,发现直线段曲率在其中点附近变化程度较小,即中点附近的像素方向值基本反映了直线段的大体走向。Through the detection and segmentation of steps (c) and (d), there may be straight line segments in the image where the difference in direction value is less than the difference threshold and the distance between the endpoints is less than the length parameter. The current subroutine will try to fuse multiple lines with these characteristics Line segments to form a single line segment. The biggest difficulty in step (e) is how to explore the nearby straight line segments according to the general trend of the current straight line segment. By running the experimental program based on Visual Studio development on the computer and adopting the method of step (c) and step (d) of the present invention, a large number of images are processed and by investigating the running results, it is found that the curvature of the straight line is relatively small near the midpoint Small, that is, the pixel direction value near the midpoint basically reflects the general trend of the straight line segment.

因此,所述的步骤(e)的具体步骤为取以中点或者在中点附近不超过50%长度参数的区域内的一点为中心,满足长度参数的子线段,以其方向值为样本,分别从当前直线段两个端点出发,按样本为走向进行搜索,如果发现与当前直线段的方向值之差小于差异阀值的直线段,则将这两条直线段进行融合;反复多次,直到不再存在可融合的直线段为止。Therefore, the specific step of the step (e) is to take the midpoint or a point in the area not exceeding 50% of the length parameter near the midpoint as the center, and the sub-line segment that satisfies the length parameter, and use its direction as a sample, Start from the two endpoints of the current straight line segment, and search according to the direction of the sample. If the difference between the direction value of the current straight line segment and the direction value is less than the difference threshold, the two straight line segments will be fused; repeated several times, until there are no more fused line segments.

所述的步骤(e)中,取以当前直线段的中点为中心,满足长度参数的子线段,以该子线段的方向值作为样本。In the step (e), take a sub-line segment centered on the midpoint of the current straight line segment and satisfy the length parameter, and use the direction value of the sub-line segment as a sample.

本发明中所述的临域与本领域技术人员所公知的定义相同,即是指以当前像素为中心的滤波窗口内,除当前像素以外的所有像素组成的集合。The neighborhood described in the present invention is the same as the definition known to those skilled in the art, that is, it refers to a set composed of all pixels except the current pixel in the filtering window centered on the current pixel.

本发明的有益效果是,本发明一种快速识别数字图像中直线段的检测方法,The beneficial effect of the present invention is that the present invention is a detection method for quickly identifying straight line segments in digital images,

(1)由于本发明是用计算机程序实施的,主要是通过分析程序的计算复杂度对检测速度进行评估。在计算复杂度上,本发明的步骤(c)是所需计算量最大的部分,由于这一部分不像霍夫变换那样对每个像素进行无差别的投影,该部分仅对非零像素及与之相邻的像素进行分析,因此它的计算复杂度为O(l·s),其中l是最长直线段的长度,s是线段总个数,而霍夫变换的计算复杂度为O(n2),n是图像的一维。(1) Since the present invention is implemented with a computer program, the detection speed is mainly evaluated by analyzing the computational complexity of the program. In terms of computational complexity, step (c) of the present invention is the part that requires the most calculations. Since this part does not perform indiscriminate projection on each pixel like the Hough transform, this part only performs non-zero pixels and The adjacent pixels are analyzed, so its computational complexity is O(l s), where l is the length of the longest straight line segment, s is the total number of line segments, and the computational complexity of the Hough transform is O( n 2 ), where n is one dimension of the image.

进一步的分析表明l和s之间存在着非常密切的关系。如果表示线段长度的l非常大,那么表示线段总数的s就会非常小。因为线段越长,其所占据的图像空间就越多,一般地,这会导致线段总数的下降。相反地,如果线段总数很多,那么最长线段的长度就不会大。因此,在l和s之间存在一种相互平衡的关系。因此,本发明步骤(c)所需计算量远小于O(n2)。Further analysis shows that there is a very close relationship between l and s. If l, which represents the length of the line segment, is very large, then s, which represents the total number of line segments, will be very small. Because the longer the line segment is, the more image space it occupies, which generally leads to a decrease in the total number of line segments. Conversely, if the total number of line segments is large, the length of the longest line segment will not be large. Therefore, there is a mutual balancing relationship between l and s. Therefore, the amount of computation required for step (c) of the present invention is far less than O(n 2 ).

步骤(d)的复杂度是Max(O(s),O(l·d)),其中d代表通过执行具有O(s)复杂度的搜索所找到的曲线段总数。由于d不可能大于s,步骤(d)的计算复杂度和步骤(c)一样,是O(l·s)。The complexity of step (d) is Max(O(s), O(l·d)), where d represents the total number of curve segments found by performing a search with O(s) complexity. Since d cannot be greater than s, the computational complexity of step (d) is the same as that of step (c), which is O(l·s).

步骤(e)的复杂度是O(s)。The complexity of step (e) is O(s).

综上,本发明所适用的计算机程序的计算复杂度是O(l·s),而根据在文献“Robust LineDetection Using Two-orthogonal Direction Image Scanning”(K.Yang,S.S.Ge,H.He,ComputerVision and Image Understanding,vol.115,no.8,pp.1207-1222,Aug.2011.)中对BU-Scan过程的分析,TODIS的复杂度至少是O(n2)。在复杂度分析上,本发明的检测速度是优于目前已知的具有较好检测精度的TODIS。In summary, the computational complexity of the computer program applicable to the present invention is O(l·s), and according to the document "Robust Line Detection Using Two-orthogonal Direction Image Scanning" (K.Yang, SSGe, H.He, ComputerVision and According to the analysis of BU-Scan process in Image Understanding, vol.115, no.8, pp.1207-1222, Aug.2011.), the complexity of TODIS is at least O(n 2 ). In terms of complexity analysis, the detection speed of the present invention is better than the currently known TODIS with better detection accuracy.

(2)本发明的精度直观体现在对数字图片中直线段的检测结果对比上。经过大量的对比,得出本发明的检测精度高于KHT和EDLines,并且本发明的精度不低于TOIDS,而TODIS是目前已知的精度最高的直线段检测方法。(2) The accuracy of the present invention is intuitively reflected in the comparison of detection results of straight line segments in digital pictures. After a large number of comparisons, it is concluded that the detection accuracy of the present invention is higher than that of KHT and EDLines, and the accuracy of the present invention is not lower than that of TOIDS, and TODIS is the most accurate detection method for straight line segments currently known.

附图说明 Description of drawings

下面结合附图和实施例对本发明进一步说明。The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

图1是本发明的主UML活动图。Figure 1 is the main UML activity diagram of the present invention.

图2是本发明的具体实施例中方向值的定义图。Fig. 2 is a definition diagram of direction values in a specific embodiment of the present invention.

图3是本发明中步骤(c)的UML活动图。Fig. 3 is a UML activity diagram of step (c) in the present invention.

图4是图3中试探性链接m个像素的UML活动图。Figure 4 is a UML activity diagram for tentatively linking m pixels in Figure 3 .

图5是图3中在3个临时列表中记录当前像素的相关信息的UML活动图。FIG. 5 is a UML activity diagram for recording relevant information of the current pixel in three temporary lists in FIG. 3 .

图6是图3中计算searchDir的UML活动图。Figure 6 is a UML activity diagram for computing searchDir in Figure 3 .

图7是图3中根据直线段长度进行记录的UML活动图。FIG. 7 is a UML activity diagram recorded according to the length of straight line segments in FIG. 3 .

图8是本发明中步骤(d)的UML活动图。Fig. 8 is a UML activity diagram of step (d) in the present invention.

图9是本发明中步骤(e)的UML活动图。Fig. 9 is a UML activity diagram of step (e) in the present invention.

图10是图9中链接端点的UML活动图。Figure 10 is a UML activity diagram of the link endpoint in Figure 9.

图11是图10中找到端点的UML活动图。Figure 11 is a UML activity diagram for finding the endpoint in Figure 10.

图12是KHT与本发明检测结果的对比图。Figure 12 is a comparison chart of the detection results of KHT and the present invention.

图13是EDLines与本发明检测结果的对比图。Fig. 13 is a comparison chart of the detection results of EDLines and the present invention.

图14是TODIS与本发明检测结果的对比图。Fig. 14 is a comparison chart of TODIS and the detection results of the present invention.

图15是标有方向值的二值图像。Figure 15 is a binary image labeled with orientation values.

图16是标有方向值和路径的二值图像。Figure 16 is a binary image labeled with orientation values and paths.

具体实施方式 Detailed ways

现在结合附图对本发明作进一步详细的说明。The present invention is described in further detail now in conjunction with accompanying drawing.

图1给出了本发明的主UML活动图。本发明包括以下步骤:Figure 1 shows the main UML activity diagram of the present invention. The present invention comprises the following steps:

(a)输入具有单位像素宽的二值图像,所述的二值图像由前景像素和背景像素两种像素组成,前景像素指包含某些图形信息的像素点,背景像素指不包含图形信息的像素点:由边缘检测提供二值图像,再使用骨骼化方法得到具有单位像素宽的二值图像;(a) Input a binary image with a unit pixel width. The binary image is composed of foreground pixels and background pixels. Foreground pixels refer to pixels containing certain graphic information, and background pixels refer to pixels that do not contain graphic information. Pixels: A binary image is provided by edge detection, and then a binary image with a unit pixel width is obtained by using the skeletalization method;

(b)设定待检测直线段的长度参数、变化参数、像素参数和范围参数:长度参数指最终检测结果中可接受直线段的最小长度;变化参数指对直线段曲率变化程度的容忍度,容忍度越大,则所检测到的直线段越接近曲线段,即直线段由几段方向具有明显差异的子线段组成;像素参数指直线段局部曲率发生明显变化时,试探性链接的像素数目;范围参数指线段融合范围参数;(b) Set the length parameter, change parameter, pixel parameter and range parameter of the straight line segment to be detected: the length parameter refers to the minimum length of the straight line segment acceptable in the final detection result; the change parameter refers to the tolerance to the degree of curvature change of the straight line segment, The greater the tolerance, the closer the detected straight line segment is to the curve segment, that is, the straight line segment is composed of several sub-line segments with obvious differences in direction; the pixel parameter refers to the number of pixels that are tentatively linked when the local curvature of the straight line segment changes significantly ;The range parameter refers to the line segment fusion range parameter;

(c)获得粗糙直线段;(c) Obtain a rough straight line segment;

(d)细分已检测到的直线段;(d) Subdividing the detected straight line segments;

(e)链接临近具有相似方向值的直线段;(e) Links are adjacent to straight line segments with similar direction values;

(f)返回所找到的直线段。(f) Return the line segment found.

下面结合图3至图11的UML活动图,分别对本发明中步骤(c)、步骤(d)、步骤(e)展开描述。Step (c), step (d), and step (e) in the present invention will be described below in conjunction with the UML activity diagrams in FIG. 3 to FIG. 11 .

这里给出在特定前提条件下,本发明的一种具体实施方式。特定前提条件包括以下几点:图像扫描顺序按从上至下,从左至右进行;滤波窗口大小为3×3。方向值由图2定义;方向值之差由下式给出:Here is a specific embodiment of the present invention under certain preconditions. Specific prerequisites include the following points: the image scanning sequence is from top to bottom and from left to right; the filter window size is 3×3. The direction values are defined by Fig. 2; the difference between the direction values is given by:

if|dir1-dir2|>4then difference=8-|dir1-dir2|;else difference=|dir1-dir2|.if|dir1-dir2|>4then difference=8-|dir1-dir2|; else difference=|dir1-dir2|.

其中dir1和dir2分别表示两条直线段的方向值,difference代表其差值;差异阀值定义为2;前景像素和背景像素分别定义为具有非0值和0值的像素。Among them, dir1 and dir2 represent the direction values of two straight line segments respectively, and difference represents their difference; the difference threshold is defined as 2; foreground pixels and background pixels are defined as pixels with non-zero and zero values, respectively.

步骤(c)的UML活动图包括图3至图7。图3中变量m表示像素参数,变量minLength表示长度参数,变量nextDirection是保存有3×3临域内的搜索起点方向值,长度为8的数组。当程序需要检查当前像素的临域时,会在这个数组中确定第一个要检查的临域像素,然后以之为起点,按与当前扫描方向相反的方向进行检查,在本实施方案中,程序将在搜索起点按逆时针方向检查。nextDirection的索引对应当前像素方向值,比如当前像素值为dir,则起点保存在索引为dir的数组成员nextDirection[dir]中,搜索起点在图3中由变量searchDir表示,它的值由下式给出:The UML activity diagram for step (c) includes Figures 3 to 7. In Figure 3, the variable m represents the pixel parameter, the variable minLength represents the length parameter, and the variable nextDirection is an array with a length of 8 that stores the direction value of the search starting point within the 3×3 neighborhood. When the program needs to check the neighborhood of the current pixel, it will determine the first neighborhood pixel to be checked in this array, and then use it as a starting point to check in the direction opposite to the current scanning direction. In this embodiment, The program will check counterclockwise at the start of the search. The index of nextDirection corresponds to the current pixel direction value. For example, if the current pixel value is dir, the starting point is stored in the array member nextDirection[dir] whose index is dir. The search starting point is represented by the variable searchDir in Figure 3, and its value is given by the following formula out:

if dir is even,then searchDir=(dir+7)mod 8;else searchDir=(dir+6)mod 8.if dir is even, then searchDir=(dir+7)mod 8; else searchDir=(dir+6)mod 8.

其中even代表偶数,mod代表取模运算。根据上式,所有方向值对应的起点都可以在程序运行前计算,然后保存在nextDirection数组中。按索引0至索引7的顺序,nextDirection成员的值依次为7,7,1,1,3,3,5,5。图3中变量Difference是8×8矩阵,每个成员的值对应了一对与之索引值具有相同数值的方向值的差,例如具有索引(3,5)的成员Difference[3,5]保存的是方向值3与方向值5之间的差,这个差由上文的方向值之差公式给出。由于方向值的个数固定为8个量,所以它们之间的差值可以预先计算,然后保存在8×8的Difference矩阵里,省去后续的重复计算,则Difference由下式给出:Among them, even represents an even number, and mod represents a modulo operation. According to the above formula, the starting points corresponding to all direction values can be calculated before the program runs, and then saved in the nextDirection array. In the order of index 0 to index 7, the values of the nextDirection member are 7, 7, 1, 1, 3, 3, 5, and 5. The variable Difference in Figure 3 is an 8×8 matrix, and the value of each member corresponds to the difference between a pair of direction values with the same value as its index value. For example, the member Difference[3,5] with the index (3,5) saves is the difference between a direction value of 3 and a direction value of 5, which is given by the difference between direction values formula above. Since the number of direction values is fixed at 8 quantities, the difference between them can be calculated in advance, and then stored in the 8×8 Difference matrix, eliminating the need for subsequent repeated calculations. The Difference is given by the following formula:

Differencedifference == 00 11 22 22 44 33 22 11 11 00 11 22 33 44 33 22 22 11 00 11 22 33 44 33 33 22 33 00 11 22 33 44 44 33 22 11 00 11 22 33 33 44 33 22 11 00 11 22 22 33 44 33 22 11 00 11

图3中变量ListOfStrings和ListOfDirections以索引为基础,分别保存了对应直线段的像素坐标和其像素方向值,例如,当前检测出n条直线段,则具有相同索引i的成员ListOfStrings[i]和ListOfDirections[i]分别保存了一条直线段所包含像素的坐标信息和方向值信息。图3变量ListOfOccurences是保存了每条直线段各方向值所对应的像素数。以图15所示的二值图像为例,图中的前景像素上的数字表示其方向值,表1给出了图15所对应的二值图像中ListOfStrings、ListOfDirections和ListOfOccurences三个变量对应的值。The variables ListOfStrings and ListOfDirections in Figure 3 are index-based, respectively saving the pixel coordinates of the corresponding straight line segment and its pixel direction value. For example, if n straight line segments are currently detected, the members ListOfStrings[i] and ListOfDirections with the same index i [i] respectively save the coordinate information and direction value information of the pixels contained in a straight line segment. The variable ListOfOccurences in Figure 3 stores the number of pixels corresponding to each direction value of each straight line segment. Taking the binary image shown in Figure 15 as an example, the numbers on the foreground pixels in the figure represent their orientation values. Table 1 shows the values corresponding to the three variables ListOfStrings, ListOfDirections and ListOfOccurences in the binary image corresponding to Figure 15 .

三个变量的索引0对应图15中的左侧线段,索引1对应右侧线段。左线段包含9个像素,右侧包含8个像素。8个ListOfStrings[1]的值保存了自上而下每个像素相对于图15左上角位置的偏移量,而ListOfStrings[1]的第9个成员ListOfStrings[0][8]为空,因为右侧线段只有8个像素。ListOfDirections[1]保存了每个像素的方向值,ListOfDirections[0]的第9个成员相应也为空,其成员顺序与ListOfStrings[1]一致,即ListOfStrings[1][i]和ListOfDirections[1][i]对应的是右线段中的同一个像素。因此ListOfDirections[1]中的值的保存顺序与ListOfStrings[1]所对应的像素顺序一致,即图15中左线段从上至下的方向值标识顺序。ListOfOccurences[1]的前8个成员分别保存了0到7方向值的像素数,其第9个成员保存了在当前状态下,具有最多像素数的方向值,观察图15,对右侧线段而言,该值显然是7,它对应的像素数为5,即右侧线段一共有5个像素的方向值是7。Index 0 of the three variables corresponds to the left line segment in Figure 15, and index 1 corresponds to the right line segment. The left line segment contains 9 pixels and the right one contains 8 pixels. The 8 values of ListOfStrings[1] store the offset of each pixel from top to bottom relative to the upper left corner of Figure 15, and the ninth member of ListOfStrings[1], ListOfStrings[0][8] is empty, because The line segment on the right is only 8 pixels long. ListOfDirections[1] saves the direction value of each pixel, and the ninth member of ListOfDirections[0] is correspondingly empty, and its member order is consistent with ListOfStrings[1], that is, ListOfStrings[1][i] and ListOfDirections[1] [i] corresponds to the same pixel in the right segment. Therefore, the storage order of the values in ListOfDirections[1] is consistent with the pixel order corresponding to ListOfStrings[1], that is, the direction value identification order of the left line segment from top to bottom in Figure 15. The first 8 members of ListOfOccurences[1] store the number of pixels of direction values from 0 to 7 respectively, and its ninth member stores the direction value with the most number of pixels in the current state. Observe Figure 15, for the line segment on the right In other words, the value is obviously 7, and the number of pixels corresponding to it is 5, that is, the direction value of the 5 pixels on the right line segment is 7.

图3还包含以下变量:dir,tempString,tempDirections和tempOccurences。变量dir表示当前像素的方向值,该变量被初始化为7,即直线段上第一个被发现的前景像素被赋予方向值7,而后发现的前景像素的方向值由其在前一像素的临域中的位置决定,在当前像素更新为新前景像素后,dir的值也更新为新像素的方向值。变量tempString,tempDirections和tempOccurences分别具有和变量ListOfStrings,ListOfDirections和ListOfOccurences相同的功能,区别在于前三者根据需要会被重新初始化,而后三者仅初始化一次,永久性地保存数据。Figure 3 also contains the following variables: dir, tempString, tempDirections, and tempOccurences. The variable dir represents the direction value of the current pixel, which is initialized to 7, that is, the first foreground pixel found on the straight line segment is given a direction value of 7, and the direction value of the foreground pixel found later is determined by its adjacent pixel value in the previous pixel. After the current pixel is updated to the new foreground pixel, the value of dir is also updated to the direction value of the new pixel. The variables tempString, tempDirections, and tempOccurences have the same functions as the variables ListOfStrings, ListOfDirections, and ListOfOccurences respectively. The difference is that the first three will be reinitialized as needed, while the latter three are only initialized once and store data permanently.

现对图3的流程做简要描述。在程序运行后,在初始化变量完成后,会设图像的最外三层像素为背景像素,然后开始逐行,逐个像素地扫描图像。发现前景像素后,图像扫描会暂停,程序会按扫描方向检查前景像素的临域,即以当前像素为中心,具有6,7,0方向值的临域,如果临域内发现了新前景像素,程序会继续查看新像素的6,7,0方向,看是否还存在前景像素,这个过程一直持续到在6,7,0方向没有发现新的前景像素为止。由于6,7,0方向是当前像素的右下角,这个过程实际上在查找线段的最右端点。A brief description of the flow in Fig. 3 is now given. After the program runs and the variables are initialized, the outermost three layers of pixels of the image will be set as the background pixels, and then the image will be scanned line by line and pixel by pixel. After the foreground pixel is found, the image scanning will pause, and the program will check the neighborhood of the foreground pixel according to the scanning direction, that is, the neighborhood with the current pixel as the center and the value of 6, 7, and 0 directions. If a new foreground pixel is found in the neighborhood, The program will continue to check the 6, 7, 0 direction of the new pixel to see if there are still foreground pixels, and this process continues until no new foreground pixel is found in the 6, 7, 0 direction. Since the 6, 7, 0 direction is the lower right corner of the current pixel, this process is actually looking for the rightmost endpoint of the line segment.

在找到最右端点后,图4所示的试探性链接开始运行。该链接实际上是不考虑m个像素的方向,试探性地链接这些像素,然后检查所链接的m个像素的最大方向值是否与试探性链接开始前线段的最大方向值相同。图4中变量searchDir和图3中的同名变量意义相同,代表搜索起点。变量length表示试探性链接的点数。变量suspiciousDirs仅在图4内部使用,它的作用和图3中ListOfOccurences相同。由于变量tempString,tempDirections和tempOccurences在图3中已经记录了线段中的部分像素,这些像素有可能最终成为线段的一部分,但在试探性链接时仍不确定,三个变量中的数据既不能保存在变量ListOfStrings,ListOfDirections和ListOfOccurences中,又不能清除,所以初始化了suspiciousDirs用于统计在试探性链接中像素方向值的分布情况,并仍使用tempString,tempDirections在原有数据不清除的条件下,继续添加试探性链接所找到的点。如果所找到的点没有m个,或suspiciousDirs[8]与tempOccurences[8]的差大于等于2,即试探性链接的具有最多像素数的方向值和试探性链接开始前所链接线段具有最多像素数的方向值的差异大于45°,则试探性链接失败,tempString,tempDirections中所保存的试探性链接像素坐标和方向值将根据length的值,进行删除。如果试探性链接成功,tempString和tempDirections保持不变,并将除索引为8以外的suspiciousDirs成员的值与具有相同索引的tempOccurences成员的值相加,保存在tempOccurences中。After finding the rightmost endpoint, the heuristic link shown in Figure 4 is run. The linking actually does not consider the direction of m pixels, heuristically links these pixels, and then checks whether the maximum direction value of the linked m pixels is the same as the maximum direction value of the line segment before the heuristic linking started. The variable searchDir in Figure 4 has the same meaning as the variable with the same name in Figure 3, representing the starting point of the search. The variable length indicates the number of points for tentative linking. The variable suspiciousDirs is only used inside Figure 4, and its role is the same as ListOfOccurences in Figure 3. Since the variables tempString, tempDirections and tempOccurences have already recorded some pixels in the line segment in Figure 3, these pixels may eventually become part of the line segment, but it is still uncertain during tentative linking, and the data in the three variables can neither be saved in Variables ListOfStrings, ListOfDirections and ListOfOccurences cannot be cleared, so suspiciousDirs is initialized to count the distribution of pixel direction values in tentative links, and tempString and tempDirections continue to add tentativeness under the condition that the original data is not cleared. Links the found points. If there are no m points found, or the difference between suspiciousDirs[8] and tempOccurences[8] is greater than or equal to 2, that is, the direction value of the tentative link has the largest number of pixels and the line segment linked before the tentative link has the largest number of pixels If the difference of direction value is greater than 45°, the tentative link fails, and the tentative link pixel coordinates and direction values saved in tempString and tempDirections will be deleted according to the value of length. If the tentative link is successful, tempString and tempDirections remain unchanged, and the value of suspiciousDirs member except index 8 is added to the value of tempOccurences member with the same index, and stored in tempOccurences.

图3在第一次试探性链接成功结束后,即开始正常链接。与试探性链接不同,正常链接在发现新前景像素时,会计算新像素与tempOccurences[8]的方向值之差,即查看新像素的方向是否和线段的大体走向一致,如果这个差小于2,则在三个临时列表中保存新像素信息,并继续正常链接;如果差大于或等于2,则开始上文所述的试探性链接,链接成功,则继续正常链接,链接失败,则检查试探性链接开始前,所找到的线段长度,大于minLength,就将三个临时列表中的数据分别保存到ListOfStrings,ListOfDirections和ListOfOccurences中,小于minlength,则重新初始化三个临时列表。在一次链接结束后,这次链接中所找到的所有前景像素会被设置为背景像素,暂停的图像扫描会在原来暂停的像素继续扫描,直到发现新前景像素为止,然后会重复上述链接过程,当扫描完图像中的最后一个像素后,图3所示的算法才会停止,图8所示的步骤(d)开始运行。Figure 3 After the first tentative link is successfully completed, the normal link starts. Different from the tentative link, when the normal link finds a new foreground pixel, it will calculate the difference between the direction value of the new pixel and tempOccurences[8], that is, check whether the direction of the new pixel is consistent with the general trend of the line segment. If the difference is less than 2, Then save the new pixel information in the three temporary lists, and continue the normal link; if the difference is greater than or equal to 2, start the tentative link described above, if the link is successful, continue the normal link, if the link fails, check the tentative link Before the start of the link, if the length of the found line segment is greater than minLength, the data in the three temporary lists will be saved to ListOfStrings, ListOfDirections and ListOfOccurences respectively; if it is less than minlength, the three temporary lists will be reinitialized. After a link ends, all the foreground pixels found in this link will be set as background pixels, and the paused image scanning will continue to scan the previously suspended pixels until new foreground pixels are found, and then the above linking process will be repeated. When the last pixel in the image is scanned, the algorithm shown in Figure 3 will stop, and step (d) shown in Figure 8 will start to run.

步骤(d)的UML活动图是图8。图8定义的主要变量有thresholdRatio,length,strings ToRemove,firstDir,secondDir,possibleSplitPositions,actualSplitPositions,groupsOfSimilarDirs,curStr,curDirs和curOccurs。变量thresholdRatio表示人工输入的变化参数,在图8中,这个值被预设为0.1。变量length表示图3中已找到的直线段总数。变量stringsToRemove用于记录被分割的线段的索引。变量firstDir和变量secondDir分别表示一条线段的最大方向值和次大方向值。变量possibleSplitPositions表示可能的分割位置。变量actualSplitPositions表示已确定的分割位置。变量groupsOfSimilarDirs表示具有相似方向值的集合列表。变量curStr,curDirs和curOccurs分别表示当前正在处理中的线段在列表ListOfStrings,ListOfDirections和ListOfOccurences中所对应的成员。The UML activity diagram for step (d) is Figure 8. The main variables defined in Figure 8 are thresholdRatio, length, strings ToRemove, firstDir, secondDir, possibleSplitPositions, actualSplitPositions, groupsOfSimilarDirs, curStr, curDirs and curOccurs. The variable thresholdRatio represents a change parameter manually input, and in FIG. 8, this value is preset as 0.1. The variable length represents the total number of straight line segments found in Figure 3. The variable stringsToRemove is used to record the index of the segment being divided. The variable firstDir and the variable secondDir represent the maximum direction value and the second maximum direction value of a line segment respectively. The variable possibleSplitPositions indicates possible split positions. The variable actualSplitPositions represents the determined split positions. The variable groupsOfSimilarDirs represents a list of sets with similar direction values. The variables curStr, curDirs and curOccurs respectively indicate the corresponding members of the line segment currently being processed in the lists ListOfStrings, ListOfDirections and ListOfOccurences.

图8所示程序将当前直线段在ListOfStrings,ListOfDirections和ListOfOccurences中所对应的成员的引用分别传递给curStr,curDirs和curOccurs,然后在curOccurs中找到firstDir和secondDir。如果firstDir和secondDir的差小于2,说明直线段上大部分的点都具有相同的方向值,没有分割的必要;如果差大于或等于2且两者的比超过了thresholdRatio,则表明直线段中至少包含了2段具有明显方向差异的子线段,程序开始查看curDirs并初始化变量possibleSplitPositions和groupsOfSimilarDirs,添加curStr第一个点的索引到possibleSplitPositions中,然后依次检查线段上除第一个和最后一个像素外,其它像素的方向值。因为第一个像素的方向值在图3中总被设定为7,而最后一个像素又往往是试探性链接结束前,方向值波动最大的点,所以去掉这两个点。在groupsOfSimilarDirs中新添加一个group并将第二个点的方向值添加给group。查看curDirs的下一个成员,并将其值与groupsOfSimilarDirs中最后添加的group所包含的所有方向值进行比较,若group不包含该值且其差小于2,则将该值添加给group;如果group包含该值且其差小于2,不做任何动作;如果差大于等于2,则在groupsOfSimilarDirs中添加一个新group并将该值添加给新group,并在possibleSplitPositions中记录当前像素在curStr中的索引。对每个像素重复上述步骤,直至倒数第二个像素为止。最后将curStr最后一个点的索引添加给possibleSplitPositions。The program shown in Figure 8 transfers the references of the members corresponding to the current straight line segment in ListOfStrings, ListOfDirections and ListOfOccurences to curStr, curDirs and curOccurs respectively, and then finds firstDir and secondDir in curOccurs. If the difference between firstDir and secondDir is less than 2, it means that most points on the straight line segment have the same direction value, and there is no need to split; if the difference is greater than or equal to 2 and the ratio of the two exceeds thresholdRatio, it means that the straight line segment has at least Contains two sub-line segments with obvious direction differences. The program starts to look at curDirs and initializes the variables possibleSplitPositions and groupsOfSimilarDirs, adds the index of the first point of curStr to possibleSplitPositions, and then checks the line segment except for the first and last pixel. Orientation values for other pixels. Because the direction value of the first pixel is always set to 7 in Figure 3, and the last pixel is often the point where the direction value fluctuates the most before the end of the tentative link, so these two points are removed. Add a new group in groupsOfSimilarDirs and add the direction value of the second point to the group. Look at the next member of curDirs and compare its value with all direction values contained in the last group added in groupsOfSimilarDirs, if the group does not contain the value and the difference is less than 2, add the value to the group; if the group contains This value and its difference is less than 2, do nothing; if the difference is greater than or equal to 2, add a new group in groupsOfSimilarDirs and add this value to the new group, and record the index of the current pixel in curStr in possibleSplitPositions. Repeat the above steps for each pixel up to the second-to-last pixel. Finally add the index of the last point of curStr to possibleSplitPositions.

结束curDirs的检查后,初始化变量actualSplitPositions。依次计算possibleSplitPositions直线段在每两个成员之间的差,如果某两个成员的差大于等于minLength,则将这两个成员添加给actualSplitPositions。在对possibleSplitPositions所有成员的检查结束后,如果actualSplitPositions非空,根据actualSplitPositions的成员,分割curStr和curDirs,在ListOfStrings和ListOfDirections中保存分割出的子线段,计算并保存相应的ListOfOccurences成员,在ListOfStrings,ListOfDirections和ListOfOccurences中保存被分割的线段;如果actualSplitPositions为空,不做任何动作。对ListOfStrings中由图3找到的每条直线段重复上述图8步骤,直至所有图3的直线段都被检查过为止。至此步骤(d)结束,步骤(e)开始运行。After checking curDirs, initialize the variable actualSplitPositions. Calculate the difference between each two members of the possibleSplitPositions line segment in turn. If the difference between two members is greater than or equal to minLength, add these two members to actualSplitPositions. After checking all members of possibleSplitPositions, if actualSplitPositions is non-empty, split curStr and curDirs according to the members of actualSplitPositions, save the split sub-line segments in ListOfStrings and ListOfDirections, calculate and save the corresponding ListOfOccurences members, in ListOfStrings, ListOfDirections and Save the split line segment in ListOfOccurences; if actualSplitPositions is empty, do nothing. Repeat the above steps in Figure 8 for each straight line segment found in Figure 3 in ListOfStrings until all the straight line segments in Figure 3 have been checked. So far step (d) is over, and step (e) starts to run.

步骤(e)的UML活动图包括图9至图11,所涉及的主要变量有detectRadius,curIndex,curStr,maxDir,isLeftConnected,isRightConnected,leftIndices,leftTerminals,rightIndice,rightTerminals,leftPattern,rightPattern,nodesOfConnection,segments,nodeCollection,segmentCollection和stringsToRemove。变量detectRadius保存了人工输入的范围参数的值,在图9中该值被预设为8。变量curIndex表示当前处理中的直线段在ListOfStrings中的索引值。变量curStr和stringsToRemove与步骤(d)中的同名变量意义相同。变量maxDir表示具有索引curIndex的直线段的最大方向值。变量isLeftConnected和isRightConnected分别表示curStr的左右两侧端点是否与其它直线段对应的端点连接在一起。变量leftIndices,rightTerminals,rightIndice和leftTerminals分别表示位于curStr左侧的直线段索引及其右端点,以及位于其右侧的直线段索引和其左端点。变量leftPattern和rightPattern分别表示重复或取反curStr的中点附近,minLength个方向值的路径。变量nodesOfConnection保存确定的要融合的线段的左端点或右端点。变量segments保存了从curStr的某个端点出发到达nodesOfConnection所保存的端点的有效路径。变量nodeCollection和segmentCollection分别包含图9中循环运行图10中所示程序产生的所有nodesOfConnection的成员和segments。The UML activity diagram of step (e) includes Figures 9 to 11. The main variables involved are detectRadius, curIndex, curStr, maxDir, isLeftConnected, isRightConnected, leftIndices, leftTerminals, rightIndice, rightTerminals, leftPattern, rightPattern, nodesOfConnection, segments, nodeCollection , segmentCollection and stringsToRemove. The variable detectRadius stores the value of the manually input range parameter, which is preset to 8 in FIG. 9 . The variable curIndex represents the index value of the straight line segment currently being processed in ListOfStrings. The variables curStr and stringsToRemove have the same meaning as the variables of the same name in step (d). The variable maxDir represents the maximum direction value for the line segment with index curIndex. The variables isLeftConnected and isRightConnected respectively indicate whether the endpoints on the left and right sides of curStr are connected to the corresponding endpoints of other straight line segments. The variables leftIndices, rightTerminals, rightIndice, and leftTerminals represent the index of the straight line segment on the left side of curStr and its right endpoint, and the index of the straight line segment on its right side and its left endpoint, respectively. The variables leftPattern and rightPattern respectively represent the path of repeating or negating the midpoint of curStr, minLength direction values. The variable nodesOfConnection holds the determined left or right endpoints of the line segments to be merged. The variable segments saves the effective path from an endpoint of curStr to the endpoint saved by nodesOfConnection. The variables nodeCollection and segmentCollection respectively contain all nodesOfConnection members and segments generated by cyclically running the program shown in Figure 10 in Figure 9 .

图像扫描顺序和步骤(c)的链接方式会导致curStr的首末成员与实际线段的左右端点相反的情况,假设图15中左侧和右侧线段分别具有索引0和1,那么按从上至下,从左至右的扫描方式,左侧线段最上面的右端点最先被发现,所以是ListOfStrings[0]中的首个成员,而其左端点最后被发现,因此也是ListOfStrings[0]中最后一个成员,而图15中右侧直线段的首末成员与左右端点一致。现在假设要链接图15中的左侧线段的右端点和右侧线段的左端点,那么融合后的直线段的前半部分包括逆序排列的ListOfStrings[0]中的成员,而后半部分包括顺序排列的ListOfStrings[1]中的成员。结合图2的方向值,可以使用图11所示的程序将curStr首末成员划分为左右端点。The image scanning order and the linking method of step (c) will lead to the situation that the first and last members of curStr are opposite to the left and right endpoints of the actual line segment. Assuming that the left and right line segments in Figure 15 have indexes 0 and 1 respectively, then press from top to Next, in the scanning method from left to right, the uppermost right endpoint of the left line segment is found first, so it is the first member in ListOfStrings[0], and its left endpoint is found last, so it is also in ListOfStrings[0] The last member, and the first and last members of the straight line segment on the right in Figure 15 are consistent with the left and right endpoints. Now assuming that the right end point of the left line segment and the left end point of the right line segment in Figure 15 are to be linked, then the first half of the fused straight line segment includes members in ListOfStrings[0] arranged in reverse order, and the second half includes members in order Members in ListOfStrings[1]. Combined with the direction value in Figure 2, the program shown in Figure 11 can be used to divide the first and last members of curStr into left and right endpoints.

图9首先运行了图10所示的链接端点程序。变量detectRadius决定了待融合直线段的范围,即对curStr,图10的程序只检测ListOfStrings中索引值位于左区间[curIndex-detectRadius,curIndex-1]和右区间[curIndex+1,curIndex+detectRadius]中的直线段,看能否存在能与curStr融合的直线段。可融合直线段的最大方向值与curStr相同,或完全相反,比如curStr的最大方向值为4,那么可融合直线段的最大方向值只能是4或0。注意在图2中,0和4实际上表示的都是水平方向的直线段。如果curStr的两侧都发现了直线段,将只有一侧的直线段会被之后的程序融合。虽然发现curStr两侧都存在可融合的直线段,但融合过程并不能马上进行,因为一旦融合,就必须从ListOfStrings中删除被融合的三条直线段,因此破坏了ListOfStrings索引的顺序,从而使被融合的线段失去了被其它线段融合的可能。因此,首先程序只检查每条直线的左端点是否能和其它直线的右端点融合,如果可以,就记录这个左端点和右端点,等所有线段都检查完了,一次性根据所记录的端点和线段信息,进行融合。Figure 9 first runs the link endpoint program shown in Figure 10. The variable detectRadius determines the range of the straight line segment to be fused, that is, for curStr, the program in Figure 10 only detects that the index value in ListOfStrings is located in the left interval [curIndex-detectRadius, curIndex-1] and the right interval [curIndex+1, curIndex+detectRadius] to see if there is a straight line segment that can be merged with curStr. The maximum direction value of the fused line segment is the same as curStr, or completely opposite. For example, the maximum direction value of curStr is 4, then the maximum direction value of the fused line segment can only be 4 or 0. Note that in Figure 2, 0 and 4 actually represent straight line segments in the horizontal direction. If straight segments are found on both sides of curStr, only the straight segments on one side will be merged by subsequent procedures. Although it is found that there are straight line segments that can be fused on both sides of curStr, the fusion process cannot be carried out immediately, because once fused, the three fused straight line segments must be deleted from the ListOfStrings, thus destroying the order of the ListOfStrings index, so that the fused The line segment loses the possibility of being merged by other line segments. Therefore, first, the program only checks whether the left endpoint of each straight line can be merged with the right endpoints of other straight lines. If so, record the left and right endpoints. After all the line segments are checked, the recorded endpoints and line segments are used at one time. information for fusion.

在leftIndices和rightIndice不为空的前提下,图10所示程序开始尝试融合curStr与对应的直线段。方法是取以ListOfDirections[curIndex]中点为中心,左右各长minLength/2的方向值为路径,检查路径上每个点的3×3临域,看保存在rightTerminals和leftTerminals中可融合直线段的端点是否存在。根据curStr的最大方向值,两个端点的路径具有相反的方向值,变量leftPattern和rightPattern分别对应左端点和右端点的路径。以图16为例,其中心部分是一条有7个像素的直线段,直线段中心用数值为5的淡色方块标识,左右两端点是标有数值5和7的深色方块,左端点左侧的灰色方块是左路径,右端点右侧的灰色方块是右路径。假设minLength为5,leftPattern依次包含方向值[5,3,5,4,4],leftPattern实际上按从右到左的顺序,重复了以中点为中心,以5为长度的直线段上各点的方向值,而直线段左端点的路径以左端点为起点,按照leftPattern中成员的值做为移动方向展开的。变量rightPattern是首先将leftPattern中成员顺序取反,即[4,4,5,3,5],然后按照将其值按图2的方向值取反得到的。在图2中,方向值3、4和5的逆依次为7、0和1,所以最后rightPattern是[0,0,1,7,1]。On the premise that leftIndices and rightIndice are not empty, the program shown in Figure 10 starts to try to fuse curStr with the corresponding straight line segment. The method is to take the midpoint of ListOfDirections[curIndex] as the center, and the left and right directions of length minLength/2 as the path, check the 3×3 neighborhood of each point on the path, and see the fusion of straight line segments stored in rightTerminals and leftTerminals Whether the endpoint exists. According to the maximum direction value of curStr, the paths of the two endpoints have opposite direction values, and the variables leftPattern and rightPattern correspond to the paths of the left endpoint and the right endpoint, respectively. Take Figure 16 as an example, its central part is a straight line segment with 7 pixels, the center of the straight line segment is marked by a light-colored square with a value of 5, the left and right end points are dark-colored squares marked with a value of 5 and 7, and the left end point is on the left side The gray square in is the left path, and the gray square to the right of the right endpoint is the right path. Assuming that minLength is 5, leftPattern contains the direction values [5, 3, 5, 4, 4] in turn, and leftPattern actually repeats each of the straight line segments with the midpoint as the center and the length of 5 in the order from right to left. The direction value of the point, and the path of the left end point of the straight line segment starts from the left end point, and expands according to the value of the member in leftPattern as the moving direction. The variable rightPattern is obtained by first reversing the order of the members in leftPattern, that is, [4, 4, 5, 3, 5], and then reversing its value according to the direction value in Figure 2. In Figure 2, the inverses of direction values 3, 4, and 5 are 7, 0, and 1 in turn, so the final rightPattern is [0, 0, 1, 7, 1].

确定路径后,当isLeftConnected为真,程序会检查leftPattern中各点的临域是否包含rightTerminals中记录的可融合线段的右端点,或当isRightConnected为真,则会检查rightPattern的各点的临域是否存在leftTerminals中的端点。如果在路径中发现了可融合线段的端点,则将其对应的线段的索引,端点,curIndex和curStr对应的端点保存在nodesOfConnection中,例如当leftPattern中某点的临域包含rightTerminals中的端点时,程序会将该端点所对应的leftIndices中的线段索引,该端点,curIndex和curStr的左端点作为一个四维向量的元素依次保存,这个向量则保存在nodesOfConnection中。注意该向量中元素的顺序始终是线段α的索引,线段α的右端点,线段β的索引,线段β的左端点,所以对于leftTerminals中的端点来说,会按照curIndex、curStr的右端点、rightIndices中的线段索引和leftTerminals中端点的顺序保存为四维向量。这个过程结束后,如果nodesOfConnection非空,则路径中从起点到接触到可融合线段端点的部分会保存在segments中,最后图10所示的程序会返回nodesOfConnection和segments,“链接端点”过程结束,程序返回图9。After determining the path, when isLeftConnected is true, the program will check whether the neighborhood of each point in leftPattern contains the right endpoint of the fusionable line segment recorded in rightTerminals, or if isRightConnected is true, it will check whether the neighborhood of each point in rightPattern exists The endpoints in leftTerminals. If the end point of the fused line segment is found in the path, the index of the corresponding line segment, the end point, the end point corresponding to curIndex and curStr are saved in nodesOfConnection, for example, when the neighborhood of a point in leftPattern includes the end point in rightTerminals, The program will store the line segment index in leftIndices corresponding to the endpoint, the endpoint, the left endpoint of curIndex and curStr as elements of a four-dimensional vector, and this vector is stored in nodesOfConnection. Note that the order of the elements in this vector is always the index of line segment α, the right endpoint of line segment α, the index of line segment β, and the left endpoint of line segment β, so for the endpoints in leftTerminals, it will follow curIndex, right endpoint of curStr, rightIndices The line segment indices in and the order of the endpoints in leftTerminals are saved as a four-dimensional vector. After this process ends, if nodesOfConnection is not empty, the part of the path from the starting point to the end point of the fused line segment will be saved in segments, and finally the program shown in Figure 10 will return nodesOfConnection and segments, and the "link endpoint" process ends. The program returns to Figure 9 .

在变量nodeCollection和segmentCollection分别保存完图10程序生成的nodesOfConnection的成员和segments之后,图9程序会重复图10程序,直至遍历ListOfStrings中的所有成员。由于nodeCollection存储了上文所提到的以四维向量保存的融合端点及其直线段的信息,程序将在stringsToRemove中记录被融合线段的索引,然后根据nodeCollection的成员,按顺序将两条线段用segmentCollection中的对应成员连接,向ListOfStrings,ListOfDirections和ListOfOccurences添加新融合的线段信息,并根据stringsToRemove中的索引信息删除原来的两条线段信息。重复这个过程,直至遍历nodeCollection所有成员为止。步骤(e)就结束了。After the variables nodeCollection and segmentCollection respectively save the nodesOfConnection members and segments generated by the program in Figure 10, the program in Figure 9 will repeat the program in Figure 10 until all members in ListOfStrings are traversed. Since nodeCollection stores the information of the fused endpoints and their straight segments saved in the four-dimensional vector mentioned above, the program will record the index of the fused line segment in stringsToRemove, and then use the segmentCollection of the two line segments in sequence according to the members of nodeCollection Corresponding member connection in , add newly fused line segment information to ListOfStrings, ListOfDirections and ListOfOccurences, and delete the original two line segment information according to the index information in stringsToRemove. Repeat this process until all members of nodeCollection are traversed. Step (e) ends.

至此,变量ListOfStrings,ListOfDirections和ListOfOccurences分别保存着所找到的直线段,其方向值记录和方向值统计信息。So far, the variables ListOfStrings, ListOfDirections and ListOfOccurences respectively save the found straight line segment, its direction value record and direction value statistical information.

图12,图13和图14分别展示了KHT,EDLines,TODIS与本发明检测结果的对比图,其中,第一列均显示的是未处理的图像,第二列显示的是现有方法的处理结果,第三列显示的是本发明的检测结果。在图12中,可以明显发现本发明的F02检测结果成功地检测到了图像左侧电线杆和变电器的直线边缘,而KHT没有检测到。本发明的F22检测结果成功检测到了图像中碟形建筑物的上边缘,而KHT则没有。本发明的F32检测结果成功检测到了图像中右下角楼房的围墙上边缘,而KHT则没有。KHT所检测到的所有直线段,通过观察图片,可以发现本发明全部都检测到了。因此,本发明的检测精度是高于KHT的。Fig. 12, Fig. 13 and Fig. 14 have shown KHT, EDLines, TODIS and the comparison figure of the detection result of the present invention respectively, and wherein, what the first row all shows is unprocessed image, and what the second row shows is the processing of existing method As a result, the third column shows the detection results of the present invention. In Fig. 12, it can be clearly found that the F02 detection result of the present invention successfully detects the straight edge of the utility pole and the transformer on the left side of the image, but KHT does not detect it. The F22 detection result of the present invention successfully detects the upper edge of the dish-shaped building in the image, but KHT does not. The F32 detection result of the present invention successfully detects the edge of the enclosure wall of the building in the lower right corner of the image, but KHT does not. All straight line segments detected by KHT can be found to be detected by the present invention by observing the pictures. Therefore, the detection accuracy of the present invention is higher than that of KHT.

在图13中,G12和G22分别显示了本发明成功检测到了G10图像中建筑物上方瓷砖间的缝隙,和G20图中女人手臂上高光与低光的直线状分界线。这些均未被EDLines所检测到,通过观察,EDLines所检测到的所有直线段,基本都被本发明检测到了。In Fig. 13, G12 and G22 respectively show that the present invention successfully detects the gap between the tiles above the building in the G10 image, and the linear dividing line between high light and low light on the woman's arm in the G20 image. These are not detected by EDLines, by observation, all straight line segments detected by EDLines are basically detected by the present invention.

在图14中,由于TODIS是目前已知的精度最高的直线段检测方法,本发明与之差距不大,但在H22所显示的检测结果上,仍能发现本发明成功检测到了摩天楼高端的玻璃缝隙,而TODIS则没有。通过观察,基本所有被TODIS检测到的直线段,本发明都检测到了。因此,在某种意义上,本发明的精度是不低于TOIDS的,但本发明的检测速度则明显高于TODIS。In Figure 14, since TODIS is currently known as the most accurate detection method for straight line segments, the present invention is not far behind it. However, in the detection results shown in H22, it can still be found that the present invention has successfully detected the high-end glass of skyscrapers. gaps, while TODIS does not. Through observation, the present invention has detected basically all straight line segments detected by TODIS. Therefore, in a sense, the accuracy of the present invention is not lower than that of TOIDS, but the detection speed of the present invention is obviously higher than that of TODIS.

以上述依据本发明的理想实施例为启示,通过上述的说明内容,相关工作人员完全可以在不偏离本项发明技术思想的范围内,进行多样的变更以及修改。本项发明的技术性范围并不局限于说明书上的内容,必须要根据权利要求范围来确定其技术性范围。Inspired by the above-mentioned ideal embodiment according to the present invention, through the above-mentioned description content, relevant workers can make various changes and modifications within the scope of not departing from the technical idea of the present invention. The technical scope of the present invention is not limited to the content in the specification, but must be determined according to the scope of the claims.

表1Table 1

Claims (9)

1.一种快速识别数字图像中直线段的检测方法,其特征在于,包括以下步骤: 1. A detection method for fast recognition of straight line segments in digital images, characterized in that it may further comprise the steps: (a)输入具有单位像素宽的二值图像,所述的二值图像由前景像素和背景像素两种像素组成,前景像素指包含图形信息的像素点,背景像素指不包含图形信息的像素点:由边缘检测提供二值图像,再使用骨骼化方法得到具有单位像素宽的二值图像; (a) Input a binary image with a unit pixel width. The binary image is composed of foreground pixels and background pixels. Foreground pixels refer to pixels that contain graphic information, and background pixels refer to pixels that do not contain graphic information. : A binary image is provided by edge detection, and then a binary image with a unit pixel width is obtained by using the skeletonization method; (b)设定待检测直线段的长度参数、变化参数、像素参数和范围参数:长度参数指最终检测结果中可接受直线段的最小长度;变化参数指对直线段曲率变化程度的容忍度,容忍度越大,则所检测到的直线段越接近曲线段,即直线段由几段方向具有明显差异的子线段组成;像素参数指直线段局部曲率发生明显变化时,对未扫描区域进行试探性链接的像素数目;范围参数指线段融合范围参数; (b) Set the length parameter, change parameter, pixel parameter and range parameter of the straight line segment to be detected: the length parameter refers to the minimum length of the straight line segment acceptable in the final detection result; the change parameter refers to the tolerance to the degree of curvature change of the straight line segment, The greater the tolerance, the closer the detected straight line segment is to the curve segment, that is, the straight line segment is composed of several sub-line segments with obvious differences in direction; the pixel parameter refers to the unscanned area when the local curvature of the straight line segment changes significantly. The number of pixels of sexual links; the range parameter refers to the line segment fusion range parameter; (c)获得粗糙直线段; (c) Obtain a rough straight line segment; (d)细分已检测到的直线段; (d) Subdividing the detected straight line segments; (e)链接临近的与当前直线段的方向值之差小于差异阀值的直线段:所述的方向值是对前景像素的临域相对于其中心位置的方向量化定义;所述的差异阀值指方向值之差的阀值,用于判断两条直线段方向是否相同的量化标准; (e) Link the adjacent straight line segment whose direction value difference with the current straight line segment is less than the difference threshold: the direction value is a quantitative definition of the direction of the neighborhood of the foreground pixel relative to its center position; the difference threshold Value refers to the threshold value of the difference between the direction values, which is used to determine whether the directions of two straight line segments are the same; (f)返回所找到的直线段; (f) Return the found line segment; 所述的步骤(c)的具体步骤为 The specific steps of the step (c) are (c1)定义方向值、方向值之差和差异阀值; (c1) Define the direction value, the difference between the direction values and the difference threshold; (c2)按一定顺序对步骤(a)中输入的二值图像进行扫描,根据当前的图像扫描顺序确定特定方向值,所述的特定方向值指与代表扫描方向的方向值的差不超过差异阀值的所有指向未扫描区域的方向值; (c2) Scan the binary image input in step (a) in a certain order, and determine a specific direction value according to the current image scanning sequence, and the specific direction value means that the difference from the direction value representing the scanning direction does not exceed the difference Threshold values for all directions pointing to unscanned areas; (c3)当发现前景像素时,暂停扫描,以前景像素为中心,只检测步骤(c2)中所述的特定方向值所指向的临域,如果发现前景像素,则继续检测步骤(c2)中所述的特定方向值指向的临域,重复这一过程,直至临域内未发现前景像素或抵达图像边界为止; (c3) When a foreground pixel is found, pause the scan, center on the foreground pixel, and only detect the neighborhood pointed to by the specific direction value described in step (c2), if a foreground pixel is found, continue to detect in step (c2) The neighborhood pointed to by the specific direction value, repeating this process until no foreground pixel is found in the neighborhood or reaches the image boundary; (c4)试探性链接:确定起始方向值,所述的起始方向值是除去步骤(c2)中所述的特定方向值后,与扫描方向临近但指向未扫描区域的方向,所述的临近是指在图像空间中2个像素之间没有间隔其它像素;以步骤(c3)中发现的最后一个前景像素为起点,检查起始方向值所指向的临域是否具有前景像素;若发现新前景像素,则设置旧前景像素为背景像素,记录其方向值并试探性链接新前景像素;重复该过程直至所链接的前景像素总数等于像素参数,或在总数未达到像素参数前未发现新前景像素; (c4) Tentative link: Determine the starting direction value, the starting direction value is the direction close to the scanning direction but pointing to the unscanned area after removing the specific direction value described in step (c2), the described Proximity means that there is no interval between two pixels in the image space; starting from the last foreground pixel found in step (c3), check whether the neighborhood pointed to by the starting direction value has a foreground pixel; if a new Foreground pixels, set the old foreground pixels as background pixels, record their orientation values and tentatively link new foreground pixels; repeat this process until the total number of linked foreground pixels is equal to the pixel parameter, or no new foreground is found before the total number does not reach the pixel parameter pixel; (c5)在试探性链接过程中,建立一个临时数据结构和一个用于永久保存的永久数据结构,所述的永久数据结构包括临时区域和永久区域,记录每个方向值的像素数并动态获取在当前时刻的最大方向值,所述的方向值的像素数指取该方向值的前景像素个数,所述的最大方向值指具有最多前景像素个数的方向值:所有在试探性链接过程中产生的每个方向值的像素数被记录在一个初始化后的临时数据结构中; (c5) During the tentative linking process, establish a temporary data structure and a permanent data structure for permanent storage, the permanent data structure includes a temporary area and a permanent area, record the number of pixels of each direction value and obtain it dynamically The maximum direction value at the current moment, the number of pixels of the direction value refers to the number of foreground pixels that take the direction value, and the maximum direction value refers to the direction value with the largest number of foreground pixels: all during the tentative linking process The number of pixels of each direction value generated in is recorded in an initialized temporary data structure; 在每次试探性连接中,若已链接的前景像素的个数未达到像素参数且当前像素周围没有发现新前景像素,则检查在试探性链接过程中所链接的前景像素的个数是否超过长度参数,若超过,则记录已链接的所有像素,并将它们标识为一条直线段,若未超过,则丢弃这些像素; In each tentative connection, if the number of linked foreground pixels does not reach the pixel parameter and no new foreground pixels are found around the current pixel, check whether the number of linked foreground pixels exceeds the length during the tentative linking process parameter, if it exceeds, record all the pixels that have been linked and identify them as a straight line segment, if not, discard these pixels; 若已链接的前景像素的个数达到像素参数且当前像素周围仍存在新前景像素,则将当前像素的方向值和上一次试探性链接的方向值记录在永久数据结构的临时区域中,并开始根据待链接前景像素的方向值与最大方向值的差,判断是否继续链接; If the number of linked foreground pixels reaches the pixel parameter and there are still new foreground pixels around the current pixel, record the direction value of the current pixel and the direction value of the last tentative link in the temporary area of the permanent data structure, and start According to the difference between the direction value of the foreground pixel to be linked and the maximum direction value, it is judged whether to continue the link; (c6)如果最大方向值和待链接前景像素的方向值之差小于差异阀值,则链接该像素并在永久数据结构的临时区域中记录其方向值,否则在当前像素位置再次启动试探性链接; (c6) If the difference between the maximum orientation value and the orientation value of the foreground pixel to be linked is less than the difference threshold, then link the pixel and record its orientation value in the temporary area of the permanent data structure, otherwise start the tentative link again at the current pixel position ; (c7)在试探性链接结束时,计算临时数据结构中的最大方向值和永久数据结构临时区域中的最大方向值之差: (c7) At the end of the heuristic linking, compute the difference between the maximum orientation value in the temporary data structure and the maximum orientation value in the temporary area of the permanent data structure: 如果差值小于差异阀值,则将临时数据结构中由试探性链接保存的前景像素和对应的方向值保存在永久数据结构的临时区域中,重复步骤(c6),直至未发现新前景像素、抵达图像边界为止;然后再根据长度参数判断是否将永久数据结构临时区域中的前景像素保存至永久区域并重新初始化临时数据结构; If the difference is less than the difference threshold, the foreground pixels and corresponding direction values saved by the tentative link in the temporary data structure are stored in the temporary area of the permanent data structure, and step (c6) is repeated until no new foreground pixels, Until the image boundary is reached; then judge whether to save the foreground pixels in the temporary area of the permanent data structure to the permanent area and re-initialize the temporary data structure according to the length parameter; 如果差值大于差异阀值,则中止链接,根据长度参数判断是否将永久数据结构临时区域中的前景像素保存至永久区域并重新初始化临时数据结构; If the difference is greater than the difference threshold, stop the link, judge whether to save the foreground pixels in the temporary area of the permanent data structure to the permanent area and reinitialize the temporary data structure according to the length parameter; 所述的步骤(d)的具体步骤为 The specific steps of the step (d) are (d1)检测存储于永久数据结构永久区域中的每条直线段所对应的方向值信息,当直线段的最大方向值和次大方向值之比超过变化参数时,则该直线段为曲线段并进行分割; (d1) Detect the direction value information corresponding to each straight line segment stored in the permanent area of the permanent data structure. When the ratio of the largest direction value to the second largest direction value of the straight line segment exceeds the change parameter, the straight line segment is a curve segment and to divide; (d2)对于步骤(d1)中发现的曲线段,从其任意端点开始,逐一检查每个像素的方向值并在初始化后的临时数据结构中记录方向值,如果该方向值与临时数据结构中已记录的任意方向值之差大于差异阀值,则标记这个像素为潜在分割点并初始化临时数据结构;重复上述步骤,直至曲线段上的所有点都被检测过; (d2) For the curve segment found in step (d1), starting from any of its endpoints, check the direction value of each pixel one by one and record the direction value in the initialized temporary data structure, if the direction value is the same as that in the temporary data structure If the difference between the recorded arbitrary direction values is greater than the difference threshold, mark this pixel as a potential segmentation point and initialize the temporary data structure; repeat the above steps until all points on the curve segment have been detected; (d3)计算每两个潜在分割点之间的距离,如果距离不小于长度参数,则将该曲线段在这两个潜在分割点进行分割; (d3) Calculate the distance between every two potential segmentation points, if the distance is not less than the length parameter, then segment the curve segment at these two potential segmentation points; 所述的步骤(e)的具体步骤为 The specific steps of the step (e) are 取以当前直线段的中点或者在中点附近不超过50%长度参数的区域内的一点为中心,满足长度参数的子线段,以其方向值为样本,分别从当前直线段两个端点出发,按样本为走向进行搜索,如果发现与当前直线段的方向值之差小于差异阀值的直线段,则将这两条直线段进行融合;反复多次,直到不再存在可融合的直线段为止。 Take the midpoint of the current straight line segment or a point in the area not exceeding 50% of the length parameter near the midpoint as the center, and the sub-line segment that satisfies the length parameter, take its direction as a sample, and start from the two endpoints of the current straight line segment respectively , search according to the direction of the sample, if the difference between the direction value of the current straight line segment and the direction value is less than the difference threshold value, the two straight line segments will be fused; repeat multiple times until there is no more straight line segment that can be fused until. 2.如权利要求1所述的一种快速识别数字图像中直线段的检测方法,其特征在于:前景像素和背景像素分别定义为具有非0值像素和0值像素,或者分别定义为值为255的像素和值小于255的像素。 2. the detection method of a kind of fast recognition straight line segment in digital image as claimed in claim 1, is characterized in that: foreground pixel and background pixel are defined as having non-zero value pixel and 0 value pixel respectively, or are respectively defined as value 255 pixels and pixels with values less than 255. 3.如权利要求1所述的一种快速识别数字图像中直线段的检测方法,其特征在于:所述的步骤(c2)中,图像扫描顺序按从上至下,从左至右顺序进行。 3. A detection method for quickly identifying straight line segments in digital images as claimed in claim 1, characterized in that: in the step (c2), the image scanning sequence is from top to bottom and from left to right . 4.如权利要求1所述的一种快速识别数字图像中直线段的检测方法,其特征在于:所述的步骤(c1)中方向值的定义由滤波窗口和方向度量单位产生,完成方向值和方向值之差的定义后,再定义差异阀值。 4. A detection method for quickly identifying straight line segments in digital images as claimed in claim 1, characterized in that: the definition of the direction value in the step (c1) is generated by the filter window and the direction measurement unit, and the direction value is completed After the definition of the difference between and the direction value, define the difference threshold. 5.如权利要求4所述的一种快速识别数字图像中直线段的检测方法,其特征在于:所述的步骤(c1)中,将数字图像中所使用的二维滤波函数的离散值的个数及其分布形状作为滤波窗口,滤波窗口大小为3×3,方向值可以由整数值定义,也可以是角度值或弧度值。 5. A detection method for quickly identifying straight line segments in a digital image as claimed in claim 4, characterized in that: in the step (c1), the discrete value of the two-dimensional filter function used in the digital image is The number and its distribution shape are used as the filter window. The size of the filter window is 3×3. The direction value can be defined by an integer value, or an angle value or a radian value. 6.如权利要求5所述的一种快速识别数字图像中直线段的检测方法,其特征在于:当方向值为角度值或弧度值时,相应的差异阀值是45°或,即当两条直线的方向值之差小于45°或时,这两条直线段被视为具有相同的方向。 6. A kind of detection method for quickly identifying straight line segments in digital images as claimed in claim 5, characterized in that: when the direction value is an angle value or a radian value, the corresponding difference threshold is 45 ° or, that is, when two Two straight line segments are considered to have the same direction when the difference between the direction values of the two straight lines is less than 45° or . 7.如权利要求5所述的一种快速识别数字图像中直线段的检测方法,其特征在于:方向值由整数值定义,定义如下:设x轴正方向的方向值为0,按逆时针方向,每隔45°的方向值依次为1、2、3、4、5、6、7;方向值之差由下式给出: 7. a kind of detection method of fast recognition straight line segment in digital image as claimed in claim 5 is characterized in that: direction value is defined by integer value, is defined as follows: set the direction value of x-axis positive direction to be 0, press counterclockwise Direction, the direction values at intervals of 45° are 1, 2, 3, 4, 5, 6, 7 in turn; the difference between the direction values is given by the following formula:  如果|dir1-dir2|>4,则difference=8-|dir1-dir2|;否则difference=|dir1-dir2|; If | dir 1- dir 2|>4, then difference =8-| dir 1- dir 2|; otherwise difference =| dir 1- dir 2|; 其中dir1dir2分别表示两条直线段的方向值,difference代表dir1dir2的差值;差异阀值定义为2。 Where dir1 and dir2 represent the direction values of the two straight line segments respectively, and difference represents the difference between dir1 and dir2 ; the difference threshold is defined as 2. 8.如权利要求7所述的一种快速识别数字图像中直线段的检测方法,其特征在于:所述的步骤(c2)中,特定方向值为6、7和0。 8. A detection method for quickly identifying straight line segments in digital images according to claim 7, characterized in that: in the step (c2), the specific direction values are 6, 7 and 0. 9.如权利要求1所述的一种快速识别数字图像中直线段的检测方法,其特征在于:所述的步骤(e)中,取以当前直线段的中点为中心,满足长度参数的子线段,以该子线段的方向值作为样本。 9. A detection method for quickly identifying a straight line segment in a digital image as claimed in claim 1, characterized in that: in the step (e), take the midpoint of the current straight line segment as the center and satisfy the length parameter Sub-segment, take the direction value of this sub-segment as a sample.
CN201210289399.0A 2012-08-14 2012-08-14 Detection method for quickly identifying straight-line segments in digital image Expired - Fee Related CN102819743B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210289399.0A CN102819743B (en) 2012-08-14 2012-08-14 Detection method for quickly identifying straight-line segments in digital image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210289399.0A CN102819743B (en) 2012-08-14 2012-08-14 Detection method for quickly identifying straight-line segments in digital image

Publications (2)

Publication Number Publication Date
CN102819743A CN102819743A (en) 2012-12-12
CN102819743B true CN102819743B (en) 2015-03-11

Family

ID=47303851

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210289399.0A Expired - Fee Related CN102819743B (en) 2012-08-14 2012-08-14 Detection method for quickly identifying straight-line segments in digital image

Country Status (1)

Country Link
CN (1) CN102819743B (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8364865B2 (en) * 2010-09-28 2013-01-29 Microsoft Corporation Data simulation using host data storage chain
CN103245667A (en) * 2013-04-08 2013-08-14 上海华力微电子有限公司 Method and system for automatically detecting mechanical scratches
CN104144342B (en) * 2013-05-08 2018-07-17 厦门趣店科技有限公司 One kind is with the symmetrical coefficient in transform domain quantization method of codomain intermediate value
CN104200196B (en) * 2014-08-12 2017-09-01 侯志勇 Guide pin position automatic identifying method in a kind of radioscopy image
CN104751177B (en) * 2015-03-26 2018-01-12 常州大学 A kind of method for being used in reference numbers image give fuzzy digit straightway
CN105513044B (en) * 2015-11-20 2018-07-17 常州大学 A kind of digital direct straight line segments recognition method based on statistical measures linear feature
CN107748887A (en) * 2017-09-30 2018-03-02 五邑大学 It is a kind of based on dominant with recessive Line segment detection planar document perspective image antidote
CN108985143B (en) * 2018-05-10 2022-03-29 国电南瑞科技股份有限公司 Method for identifying iron tower structure of overhead transmission line based on unmanned aerial vehicle image
CN110569845A (en) * 2019-09-12 2019-12-13 苏州大学 A test paper image correction method and related device
CN115661453B (en) * 2022-10-25 2023-08-04 腾晖科技建筑智能(深圳)有限公司 Tower crane object detection and segmentation method and system based on downward view camera

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102156884A (en) * 2011-04-25 2011-08-17 中国科学院自动化研究所 Straight segment detecting and extracting method
CN102270299A (en) * 2011-08-24 2011-12-07 复旦大学 Edge connection algorithm realized in parallel based on breakpoints

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006523345A (en) * 2003-04-03 2006-10-12 ダブリン シティ ユニバーシティ Shape matching method for indexing and searching multimedia data

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102156884A (en) * 2011-04-25 2011-08-17 中国科学院自动化研究所 Straight segment detecting and extracting method
CN102270299A (en) * 2011-08-24 2011-12-07 复旦大学 Edge connection algorithm realized in parallel based on breakpoints

Also Published As

Publication number Publication date
CN102819743A (en) 2012-12-12

Similar Documents

Publication Publication Date Title
CN102819743B (en) Detection method for quickly identifying straight-line segments in digital image
CN112132897A (en) A visual SLAM method for semantic segmentation based on deep learning
CN108280450B (en) A method for detecting highway pavement based on lane lines
Micusik et al. Descriptor free visual indoor localization with line segments
CN105957007A (en) Image stitching method based on characteristic point plane similarity
CN106372642A (en) Rapid ellipse detection method based on contour curve segmentation arc merging and combination
JP6932402B2 (en) Multi-gesture fine division method for smart home scenes
US20250005853A1 (en) Three-dimensional building model generation based on classification of image elements
Yang et al. Multiple object tracking with kernelized correlation filters in urban mixed traffic
CN110378906B (en) An Ellipse Detection Method Based on Chord Tangent Distance
WO2020114321A1 (en) Point cloud denoising method, image processing device and apparatus having storage function
CN108171695A (en) A kind of express highway pavement detection method based on image procossing
CN104715250B (en) cross laser detection method and device
WO2023273010A1 (en) High-rise littering detection method, apparatus, and device, and computer storage medium
CN103093226B (en) A kind of building method of the RATMIC descriptor for characteristics of image process
CN110738695B (en) A Method for Eliminating Mismatched Image Feature Points Based on Local Transformation Model
JP2016009448A (en) Determination device, determination method, and determination program
CN108550166A (en) A kind of spatial target images matching process
Ecins et al. Seeing behind the scene: Using symmetry to reason about objects in cluttered environments
CN1256696C (en) Image Processing Method for Ellipse Detection Using Restricted Random Hough Transform
Zhou et al. A high-precision ellipse detection method based on quadrant representation and top-down fitting
CN106802149B (en) A Fast Sequence Image Matching Navigation Method Based on High-Dimensional Combination Features
CN105138979A (en) Method for detecting the head of moving human body based on stereo visual sense
CN105957074B (en) Line match method and system based on the description of V-type intersection point and local homography matrix
CN104992433A (en) Multispectral image registration method and device based on line segment matching

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20210827

Address after: 215222 Room 401, building 23, No. 1188, West 2nd Ring Road, Shengze Town, Wujiang District, Suzhou City, Jiangsu Province

Patentee after: Suzhou qishuo Information Technology Co.,Ltd.

Address before: Gehu Lake Road Wujin District 213164 Jiangsu city of Changzhou province No. 1

Patentee before: CHANGZHOU University

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20150311