Line detection: Difference between revisions

Content deleted Content added
mNo edit summary
mNo edit summary
 
(48 intermediate revisions by 17 users not shown)
Line 1:
{{Short description|Algorithm}}
{{multiple issues|
In image processing, a '''line detection''' is an algorithm that takes a collection of ''n'' [[edge detection|edge points]] thatand arefinds adjacentall andthe havelines theon samewhich directionthese edge points lie.<ref name=":0">{{Cite book|url=https://www.worldcat.org/oclc/491888664|title=Digital image processing and analysis : human and computer vision applications with CVIPtools|last=E.Umbaugh|first=Umbaugh,Scott ScottE.|date=2011|publisher=CRC Press|others=Umbaugh, Scott E.|isbn=9781439802052|edition=2nd ed|___location=Boca Raton, FL|oclc=491888664}}</ref> Line detection is an algorithm that take a collection of n edge points and find all the lines on which these edge points lie. The most popular line detectors are the '''[[Hough transform''']] and '''[[Kernel (image processing)|convolution''' ]]-based techniquetechniques. <ref>{{Cite web|url=http://www.mathworks.com/help/images/ref/hough.html|title=Hough transform - MATLAB hough|website=www.mathworks.com|access-date=2018-04-23}}</ref>
{{essay-like|date=April 2018}}
{{orphan|date=April 2018}}
{{refimprove|date=April 2018}}
}}
[[Category:Image processing]]
In image processing, a line is a collection of edge points that are adjacent and have the same direction.<ref name=":0">{{Cite book|url=https://www.worldcat.org/oclc/491888664|title=Digital image processing and analysis : human and computer vision applications with CVIPtools|last=E.|first=Umbaugh, Scott|date=2011|publisher=CRC Press|others=Umbaugh, Scott E.|isbn=9781439802052|edition=2nd ed|___location=Boca Raton, FL|oclc=491888664}}</ref> Line detection is an algorithm that take a collection of n edge points and find all the lines on which these edge points lie. The most popular line detectors are the '''Hough transform''' and '''convolution''' based technique. <ref>{{Cite web|url=http://www.mathworks.com/help/images/ref/hough.html|title=Hough transform - MATLAB hough|website=www.mathworks.com|access-date=2018-04-23}}</ref>
 
== Hough transform ==
'''The [[Hough transform''']]<ref name="Caltech">{{Cite web|url=http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/HoughTrans_lines_09.pdf|title=Line Detection by Hough transformation}}</ref> can be used to detect lines and the output is a parametric description of the lines in an image, for example ρ = r cos(θ) + c sin(θ).<ref name=":0" /> If wethere haveis a line in oura row and column based image space, weit can definebe that line bydefined ρ, the distance from the origin to the line along a perpendicular to the line, and θ, the angle of the perpendicular projection from the origin to the line measured in degrees clockwise from the positive row axis. [2] Therefore, a line in the image corresponds to a point in the Hough space.[<ref><nowiki>{{cite web|url=http://vision.stanford.edu/teaching/cs231a_autumn1112/lecture/lecture4_edges_lines_cs231a_marked.pdf |title=Finding lines: from detection to model fitting |first=Fei-Fei |last=Li |date=10 October 2011 |publisher=Stanford Vision Lab}}</nowikiref> The Hough space for lines has therefore these two dimensions θ and ρ, and a line is represented by a single point corresponding to a unique set of these parameters. The Hough transform can then be implemented by choosing a set of values of ρ and θ to use. For each pixel ({{var|r}}, {{var|c}}) in the image, compute r cos(θ) + c sin(θ) for each values of θ, and place the result in the appropriate position in the (ρ, θ) array. At the end, the values of (ρ, θ) with the highest values in the array will correspond to strongest lines in the image
</ref>] The Hough space for lines has therefore these two dimensions θ and ρ, and a line is represented by a single point corresponding to a unique set of these parameters.
 
== Convolution-based technique ==
In a '''convolution'''[[Kernel (image processing)|convolution]]-based technique, the line detector operator consists of a convolution masks tuned to detect the presence of lines of a particular width n and a θ orientation. Here are the four convolution masks to detect horizontal, vertical, oblique (+45 degrees), and oblique (-45−45 degrees) lines in an image.
 
<references group="https://homepages.inf.ed.ac.uk/rbf/HIPR2/linedet.htm" />a) Horizontal mask(R1)
{| class="wikitable"
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
|-
| 2
| 2
| 2
|-
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
|}
(b) Vertical (R3)
{| class="wikitable"
| −1
|<nowiki>-1</nowiki>
| 2
| −1
|<nowiki>-1</nowiki>
|-
| −1
|<nowiki>-1</nowiki>
| 2
| −1
|<nowiki>-1</nowiki>
|-
| −1
|<nowiki>-1</nowiki>
| 2
| −1
|<nowiki>-1</nowiki>
|}
(C) Oblique (+45 degrees)(R2)
{| class="wikitable"
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
| 2
|-
| −1
|<nowiki>-1</nowiki>
| 2
| −1
|<nowiki>-1</nowiki>
|-
| 2
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
|}
(d) Oblique (-45−45 degrees)(R4)
{| class="wikitable"
| 2
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
|-
| −1
|<nowiki>-1</nowiki>
| 2
| −1
|<nowiki>-1</nowiki>
|-
| −1
|<nowiki>-1</nowiki>
| −1
|<nowiki>-1</nowiki>
| 2
|}
<ref name=":1" />
 
inIn practice, masks are run over the the image and the responses are combinecombined given by the following equation:
 
'''R(x, y) = max(|R1 (x, y)|, |R2 (x, y)|, |R3 (x, y)|, |R4 (x, y)|''')
Line 80 ⟶ 76:
 
|}
As can be seen below, if mask is overlay on the image (horizontal line), multiply the coincident values, and sum all these results, the output will be the (convolved image) . For example, (-1−1)(0)+(-1−1)(0)+(-1−1)(0) + (2)(1) +(2)(1)+(2)(1) + (-1−1)(0)+(-1−1)(0)+(-1−1)(0) = 6 pixels on the second row, second column in the (convolved image) starting from the upper left corner of the horizontal lines .<ref name=":0" /> page 82
 
== Example: ==
{| class="wikitable sortable"
|
Line 150 ⟶ 148:
| -
|-
| -1−1
| -1−1
| -1−1
|
|
Line 178 ⟶ 176:
|
|-
| -1−1
| -1−1
| -1−1
|
|
Line 248 ⟶ 246:
These masks above are tuned for light lines against a dark background, and would give a big negative response to dark lines against a light background.<ref name=":1">{{Cite web|url=https://homepages.inf.ed.ac.uk/rbf/HIPR2/linedet.htm|title=Line Detection|website=homepages.inf.ed.ac.uk|access-date=2018-04-23}}</ref>
 
== Code example ==
Example:
The code was used to detect only the vertical lines in an image using Matlab and the result is below. The original image is the one on the top and the result is below it. As can be seen on the picture on the right, only the vertical lines were detected
 
[[File:Testbuilding.jpg|thumb|Original Image]]
Lets take a look at this examples:
[[File:LineImage.png|thumb|line detection]]
 
The code below was used to detect only the vertical lines in an image using Matlab<syntaxhighlight lang="matlab" line="1">
clear all
clc
% this MATLAB program will only detect vertical lines in an image
%benzene = imread('benzene.png');
%building = imread('building.tifjpg'); % This will upload the image building
tol = 5; % define a tolerance in the angle to account for noise or edge
crazy=imread('crazypic.jpg');
building=rgb2gray(crazy);
tol = 5;%define a tolerance in the angle to account for noise or edge
% that may look vertical but when the angle is computed
% it may not appear to be
[~, angle] = imgradient(building);
out = (angle >= 180 - tol | angle <= -180 + tol);
%this part will filter the line
out_filter = bwareaopen(out, 50);
figure, imshow(crazybuilding), title('Original Image');
figure, imshow(out_filter), title('Detected Lines');
</syntaxhighlight>
</syntaxhighlight><references />[http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/HoughTrans_lines_09.pdf]
 
==See also==
* [[Digital image processing]]
* [[Canny edge detector]]
* [[Sobel operator]]
*
 
==References==
{{reflist}}
 
[[Category:Image processing]]
__FORCETOC__