CN111445510A - Method for detecting straight line in image - Google Patents
Method for detecting straight line in image Download PDFInfo
- Publication number
- CN111445510A CN111445510A CN202010211840.8A CN202010211840A CN111445510A CN 111445510 A CN111445510 A CN 111445510A CN 202010211840 A CN202010211840 A CN 202010211840A CN 111445510 A CN111445510 A CN 111445510A
- Authority
- CN
- China
- Prior art keywords
- roi
- gradient
- gradient direction
- edge points
- straight line
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 22
- 239000011159 matrix material Substances 0.000 claims abstract description 10
- 238000012545 processing Methods 0.000 abstract description 4
- 238000004364 calculation method Methods 0.000 description 3
- 238000001514 detection method Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000005259 measurement Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 1
- 238000002474 experimental method Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/60—Analysis of geometric attributes
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/10—Image acquisition modality
- G06T2207/10004—Still image; Photographic image
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20092—Interactive image processing based on input by user
- G06T2207/20104—Interactive definition of region of interest [ROI]
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Geometry (AREA)
- Image Analysis (AREA)
Abstract
A method for detecting straight lines in an image comprises the following steps: converting the image ROI subgraph into a gray level map; calculating gradient values of each pixel point in the ROI subgraph in the x direction and the y direction to form gradient matrixes dx and dy; calculating a gradient direction angle matrix da; extracting all edge points in the ROI subgraph; extracting gradient direction angles of all edge points from the gradient direction angle matrix da to form a gradient direction array arrungs; equally dividing an angle interval [0, 360] into a plurality of subintervals at intervals of n, dividing the gradient direction angle of each edge point in the arrAngs into corresponding subintervals, counting the number of the gradient direction angles of the edge point in each subinterval, and finally reading all the edge points in the subintervals with the largest number; all the edge points read are fitted to a straight line. The invention belongs to the field of image processing, and can efficiently and accurately detect a target straight line with the longest length in an image ROI (region of interest) with a complex texture background.
Description
Technical Field
The invention relates to a method for detecting straight lines in an image, and belongs to the field of image processing.
Background
In the field Of image processing, many scenes need to detect straight lines Of ROI (region Of interest) regions in a target image, the background Of the ROI regions contains many complex textures, and each ROI region contains one or more straight line segments, and often the straight line segment with the longest length in the ROI region needs to be detected.
In the prior art, line detection generally uses a hough transform method or a gradient calculation-based method:
1. the method based on Hough transform has certain robustness, but Hough detection is time-consuming, and a complete straight line is easily split into a plurality of straight lines, which is not beneficial to subsequent analysis and processing.
2. A typical representative method of the gradient calculation-based method is L SD line segment detection algorithm, the method calculates the gradient of each pixel point in a target image, generates a gradient direction consistency connected region containing a target straight line according to the gradient amplitude and the gradient direction, and then obtains parameters of the straight line segment from the connected region.
That is, both of the above-mentioned typical methods are easy to split the longest straight line segment in the ROI region of the image into a plurality of straight lines. Therefore, how to efficiently and accurately detect the longest target straight line in the ROI region of the image with the complex texture background has become a technical problem that technicians generally pay attention to.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method for detecting a straight line in an image, which can efficiently and accurately detect a target straight line with the longest length in an ROI region of an image with a background with complex texture.
In order to achieve the above object, the present invention provides a method for detecting a straight line in an image, comprising:
step one, extracting a picture of an ROI (region of interest) region from an image to be detected, namely an ROI subgraph for short, converting the ROI subgraph into a gray-scale image, and performing Gaussian denoising;
step two, calculating gradient values of each pixel point in the ROI subgraph in the x direction and the y direction respectively, and forming gradient values of all the pixel points in the x direction and the y direction into gradient matrixes dx and dy respectively according to coordinates of the pixel points;
step three, calculating a gradient direction angle matrix da according to the gradient matrixes dx and dy: da ═ atan (dy/dx), and the gradient direction angle has a value range of [0, 360 ];
step four, extracting all edge points in the ROI subgraph;
step five, extracting the gradient direction angles of all edge points in the ROI subgraph from the gradient direction angle matrix da according to the edge point coordinates, and forming a gradient direction array arrAngs by the extracted gradient direction angles of the edge points;
equally dividing an angle interval [0, 360] into a plurality of sub-intervals by taking n as an interval, dividing the gradient direction angle of each edge point in a gradient direction array arrungs into corresponding sub-intervals, counting the number of the gradient direction angles of the edge points contained in each sub-interval, and finally reading all the edge points contained in the sub-interval with the largest number, wherein the edge points are points on a to-be-detected straight line;
and seventhly, fitting all the edge points read from the subintervals into a straight line, wherein the straight line is the straight line with the longest length detected from the ROI area of the image to be detected, and acquiring the straight line parameters.
Compared with the prior art, the invention has the beneficial effects that: the method can accurately detect the straight line with the longest length from the ROI of the image no matter under the background of simple or complex textures, a long straight line segment cannot be split into a plurality of segments, and the detected straight line is fitted with the filtered edge points, so that the real edge in the image can be more approximated, and higher precision is provided for image measurement.
Drawings
FIG. 1 is a flow chart of a method for detecting a line in an image according to the present invention.
Fig. 2 is a diagram of effects of an embodiment to which the present invention is applied.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail with reference to the accompanying drawings.
As shown in fig. 1, the method for detecting a straight line in an image according to the present invention includes:
extracting a picture Of an ROI (region Of interest) region from an image to be detected, namely an ROI subgraph for short, converting the ROI subgraph into a gray-scale image, and performing Gaussian denoising;
step two, calculating gradient values of each pixel point in the ROI subgraph in the x direction and the y direction respectively by using a sobel operator, and forming gradient values of all the pixel points in the x direction and the y direction into gradient matrixes dx and dy respectively according to coordinates of the pixel points;
step three, calculating a gradient direction angle matrix da according to the gradient matrixes dx and dy: da ═ atan (dy/dx), where dy and dx are matrices of the same size, dy/dx represents the division of corresponding elements in two matrices of the same size, and the result is also a matrix of the same size, atan (dy/dx) represents the calculation for each element of the matrix, and the range of gradient direction angles is [0, 360 ];
step four, extracting all edge points in the ROI subgraph by using a canny operator;
step five, extracting the gradient direction angles of all edge points in the ROI subgraph from the gradient direction angle matrix da according to the edge point coordinates, and forming a gradient direction array arrAngs by the extracted gradient direction angles of the edge points;
equally dividing an angle interval [0, 360] into a plurality of sub-intervals by taking n as an interval, dividing the gradient direction angle of each edge point in a gradient direction array arrungs into corresponding sub-intervals, counting the number of the gradient direction angles of the edge points contained in each sub-interval, and finally reading all the edge points contained in the sub-interval with the largest number, wherein the edge points are points on a to-be-detected straight line; where n is a natural number not greater than 3, which may be set according to actual business needs, for example, when n is 1, the angle interval [0, 360] is equally divided into 360 sub-intervals, and when n is 2, the angle interval [0, 360] is equally divided into 180 sub-intervals;
and seventhly, fitting all the edge points read from the subintervals into a straight line, wherein the straight line is the straight line with the longest length detected from the ROI area of the image to be detected, and acquiring the straight line parameters.
Step six can also further include:
step 61, equally dividing the angle interval [0, 360] into a plurality of subintervals at intervals of n, and then projecting the gradient direction angles of all edge points in the gradient direction array arrungs into the corresponding subintervals to generate a gradient direction angle projection histogram;
and step 62, selecting a sub-interval with the largest number of edge points from the gradient direction angle projection histogram, and reading all the edge points in the sub-interval.
According to experiments, the method can accurately detect the straight line with the longest length from the ROI of the image under the background of simple or complex textures, the long straight line segment cannot be split into a plurality of segments, and the detected straight line is fitted with the filtered edge points, so that the real edge in the image can be more approximated, and higher precision is provided for image measurement. FIG. 2 is an effect graph of an embodiment of the present invention, wherein (a) is a gray scale graph after ROI subgraph transformation; (b) step four, extracting all edge points in the ROI subgraph by using a canny operator; (c) generating a gradient direction angle projection histogram in the step six; (d) step six, all edge points obtained from the selected subintervals are obtained; (e) is the straight line with the longest length detected from the image ROI area by the invention.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.
Claims (5)
1. A method for detecting a straight line in an image is characterized by comprising the following steps:
step one, extracting a picture of an ROI (region of interest) region from an image to be detected, namely an ROI subgraph for short, converting the ROI subgraph into a gray-scale image, and performing Gaussian denoising;
step two, calculating gradient values of each pixel point in the ROI subgraph in the x direction and the y direction respectively, and forming gradient values of all the pixel points in the x direction and the y direction into gradient matrixes dx and dy respectively according to coordinates of the pixel points;
step three, calculating a gradient direction angle matrix da according to the gradient matrixes dx and dy: da ═ atan (dy/dx), and the gradient direction angle has a value range of [0, 360 ];
step four, extracting all edge points in the ROI subgraph;
step five, extracting the gradient direction angles of all edge points in the ROI subgraph from the gradient direction angle matrix da according to the edge point coordinates, and forming a gradient direction array arrAngs by the extracted gradient direction angles of the edge points;
equally dividing an angle interval [0, 360] into a plurality of sub-intervals by taking n as an interval, dividing the gradient direction angle of each edge point in a gradient direction array arrungs into corresponding sub-intervals, counting the number of the gradient direction angles of the edge points contained in each sub-interval, and finally reading all the edge points contained in the sub-interval with the largest number, wherein the edge points are points on a to-be-detected straight line;
and seventhly, fitting all the edge points read from the subintervals into a straight line, wherein the straight line is the straight line with the longest length detected from the ROI area of the image to be detected, and acquiring the straight line parameters.
2. The method of claim 1, wherein in step two, a sobel operator is used to calculate the gradient value of each pixel point in the ROI subgraph in the x and y directions, respectively.
3. The method of claim 1, wherein in step four, a canny operator is used to extract all edge points in the ROI subgraph.
4. The method according to claim 1, wherein in step seven, all the edge points read from the subintervals are fitted to a straight line using ransac algorithm.
5. The method of claim 1, wherein step six further comprises:
step 61, equally dividing the angle interval [0, 360] into a plurality of subintervals at intervals of n, and then projecting the gradient direction angles of all edge points in the gradient direction array arrungs into the corresponding subintervals to generate a gradient direction angle projection histogram;
and step 62, selecting a sub-interval with the largest number of edge points from the gradient direction angle projection histogram, and reading all the edge points in the sub-interval.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010211840.8A CN111445510A (en) | 2020-03-24 | 2020-03-24 | Method for detecting straight line in image |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010211840.8A CN111445510A (en) | 2020-03-24 | 2020-03-24 | Method for detecting straight line in image |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111445510A true CN111445510A (en) | 2020-07-24 |
Family
ID=71652413
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010211840.8A Pending CN111445510A (en) | 2020-03-24 | 2020-03-24 | Method for detecting straight line in image |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111445510A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111652825A (en) * | 2020-08-06 | 2020-09-11 | 上海海栎创微电子有限公司 | Edge tracking straight line segment rapid detection device and method based on gradient direction constraint |
CN111986221A (en) * | 2020-09-07 | 2020-11-24 | 北京凌云光技术集团有限责任公司 | Edge evaluation method and device based on gray scale or position information |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102663395A (en) * | 2012-03-05 | 2012-09-12 | 西北工业大学 | A straight line detection method based on self-adaptation multi-scale fast discrete Beamlet transform |
CN109558908A (en) * | 2018-11-28 | 2019-04-02 | 西安邮电大学 | A kind of determination method of given area optimal edge |
CN110210451A (en) * | 2019-06-13 | 2019-09-06 | 重庆邮电大学 | A kind of zebra line detecting method |
CN110660071A (en) * | 2019-08-23 | 2020-01-07 | 中山市奥珀金属制品有限公司 | Automatic edge detection double-threshold setting method and system |
-
2020
- 2020-03-24 CN CN202010211840.8A patent/CN111445510A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102663395A (en) * | 2012-03-05 | 2012-09-12 | 西北工业大学 | A straight line detection method based on self-adaptation multi-scale fast discrete Beamlet transform |
CN109558908A (en) * | 2018-11-28 | 2019-04-02 | 西安邮电大学 | A kind of determination method of given area optimal edge |
CN110210451A (en) * | 2019-06-13 | 2019-09-06 | 重庆邮电大学 | A kind of zebra line detecting method |
CN110660071A (en) * | 2019-08-23 | 2020-01-07 | 中山市奥珀金属制品有限公司 | Automatic edge detection double-threshold setting method and system |
Non-Patent Citations (3)
Title |
---|
KUO-LIANG CHUNG 等: "New orientation-based elimination approach for accurate line-detection", 《PATTERN RECOGNITION LETTERS》, 13 September 2009 (2009-09-13), pages 11 - 19 * |
徐德 著: "《显微视觉测量与控制》", 31 December 2014, pages: 66 - 67 * |
汤伟等: "基于改进霍夫变换的水面无人船水界线检测方法", 《科学技术与工程》, vol. 18, no. 31, 30 November 2018 (2018-11-30), pages 36 - 41 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111652825A (en) * | 2020-08-06 | 2020-09-11 | 上海海栎创微电子有限公司 | Edge tracking straight line segment rapid detection device and method based on gradient direction constraint |
CN111986221A (en) * | 2020-09-07 | 2020-11-24 | 北京凌云光技术集团有限责任公司 | Edge evaluation method and device based on gray scale or position information |
CN111986221B (en) * | 2020-09-07 | 2024-05-24 | 凌云光技术股份有限公司 | Edge evaluation method and device based on gray level or position information |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11443437B2 (en) | Vibe-based three-dimensional sonar point cloud image segmentation method | |
CN109886928B (en) | Target cell marking method, device, storage medium and terminal equipment | |
CN112818988A (en) | Automatic reading identification method and system for pointer instrument | |
CN112561940B (en) | Dense multi-target parameter extraction method and device and terminal equipment | |
CN110335233B (en) | Highway guardrail plate defect detection system and method based on image processing technology | |
CN110909640A (en) | Method and device for determining water level line, storage medium and electronic device | |
CN106340010B (en) | A kind of angular-point detection method based on second order profile difference | |
CN110110667B (en) | Processing method and system of diatom image and related components | |
CN113674220A (en) | Image difference detection method, detection device and storage medium | |
CN110276759B (en) | Mobile phone screen bad line defect diagnosis method based on machine vision | |
CN111445510A (en) | Method for detecting straight line in image | |
CN113642582A (en) | Ammeter reading identification method and device, electronic equipment and storage medium | |
CN107133964B (en) | Image matting method based on Kinect | |
CN107392948B (en) | Image registration method of amplitude-division real-time polarization imaging system | |
CN114821274A (en) | Method and device for identifying state of split and combined indicator | |
CN112560839A (en) | Automatic identification method and system for reading of pointer instrument | |
CN110490865B (en) | Stud point cloud segmentation method based on high light reflection characteristic of stud | |
CN109801428B (en) | Method and device for detecting edge straight line of paper money and terminal | |
CN114255352A (en) | River channel extraction method and device and computer readable storage medium | |
CN113554688B (en) | O-shaped sealing ring size measurement method based on monocular vision | |
CN113421301B (en) | Method and system for positioning central area of field crop | |
Ying et al. | Research on an automatic counting method for steel bars' image | |
CN114663681A (en) | Method for reading pointer type meter and related product | |
CN114742849A (en) | Leveling instrument distance measuring method based on image enhancement | |
CN110298799B (en) | PCB image positioning correction method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200724 |