Content deleted Content added
formatting |
mNo edit summary |
||
(44 intermediate revisions by 17 users not shown) | |||
Line 1:
{{Short description|Algorithm}}
In image processing,
[[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 ==
== Convolution-based technique ==
In a
<references group="https://homepages.inf.ed.ac.uk/rbf/HIPR2/linedet.htm" />a) Horizontal mask(R1)
{| class="wikitable"
| −1
| −1
| −1
|-
| 2
| 2
| 2
|-
| −1
| −1
| −1
|}
(b) Vertical (R3)
{| class="wikitable"
| −1
| 2
| −1
|-
| −1
| 2
| −1
|-
| −1
| 2
| −1
|}
(C) Oblique (+45 degrees)(R2)
{| class="wikitable"
| −1
| −1
| 2
|-
| −1
| 2
| −1
|-
| 2
| −1
| −1
|}
(d) Oblique (
{| class="wikitable"
| 2
| −1
| −1
|-
| −1
| 2
| −1
|-
| −1
| −1
| 2
|}
<ref name=":1" />
'''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)
{| class="wikitable sortable"
|
Line 150 ⟶ 148:
| -
|-
|
|
|
|
|
Line 178 ⟶ 176:
|
|-
|
|
|
|
|
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]]
[[File:LineImage.png|thumb|line detection]]
clear all
clc
% this MATLAB program will only detect vertical lines in an image
tol = 5; % define a tolerance in the angle to account for noise or edge▼
▲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(
figure, imshow(out_filter), title('Detected Lines');
</syntaxhighlight>
==See also==
* [[Digital image processing]]
* [[Canny edge detector]]
* [[Sobel operator]]
*
==References==
{{reflist}}
▲[[Category:Image processing]]
__FORCETOC__
|