Line detection
![]() | This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
No issues specified. Please specify issues, or remove this template. |
In image processing, a line is a collection of edge points that are adjacent and have the same direction.[1] 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. [2]
Hough transform 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(θ).[1] If we have a line in our row and column based image space, we can define that line by ρ, 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.[[3]] 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.
In a 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 degrees) lines in an image.
a) Horizontal mask(R1)
-1 | -1 | -1 |
2 | 2 | 2 |
-1 | -1 | -1 |
(b) Vertical (R3)
-1 | 2 | -1 |
-1 | 2 | -1 |
-1 | 2 | -1 |
(C) Oblique (+45 degrees)(R2)
-1 | -1 | 2 |
-1 | 2 | -1 |
2 | -1 | -1 |
(d) Oblique (-45 degrees)(R4)
2 | -1 | -1 |
-1 | 2 | -1 |
-1 | -1 | 2 |
in practice, masks are run over the the image and the responses are combine given by the following equation:
R(x, y) = max(|R1 (x, y)|, |R2 (x, y)|, |R3 (x, y)|, |R4 (x, y)|)
If R(x, y) > T, then discontinuity
Horizontal line | convolved image | |||||||||||
0 | 0 | 0 | 0 | - | - | - | - | |||||
1 | 1 | 1 | 1 | = | - | 6 | 6 | - | ||||
Mask | * | 0 | 0 | 0 | 0 | - | - | - | - | |||
-1 | -1 | -1 | ||||||||||
2 | 2 | 2 | ||||||||||
-1 | -1 | -1 | ||||||||||
* | Vertical line | convolved image | ||||||||||
0 | 0 | 1 | 0 | - | - | - | - | |||||
0 | 0 | 1 | 0 | = | - | 0 | 0 | - | ||||
0 | 0 | 1 | 0 | - | - | - | - |
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.[4]
Example:
Lets take a look these examples:
clear all
clc
%benzene = imread('benzene.png');
%building = imread('building.tif');
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);
out_filter = bwareaopen(out, 50);
figure,imshow(crazy),title('Original Image');
figure,imshow(out_filter),title('Detected Lines');
- ^ a b E., Umbaugh, Scott (2011). Digital image processing and analysis : human and computer vision applications with CVIPtools. Umbaugh, Scott E. (2nd ed ed.). Boca Raton, FL: CRC Press. ISBN 9781439802052. OCLC 491888664.
{{cite book}}
:|edition=
has extra text (help)CS1 maint: multiple names: authors list (link) - ^ "Hough transform - MATLAB hough". www.mathworks.com. Retrieved 2018-04-23.
- ^ http://vision.stanford.edu/teaching/cs231a_autumn1112/lecture/lecture4_edges_lines_cs231a_marked.pdf
- ^ a b "Line Detection". homepages.inf.ed.ac.uk. Retrieved 2018-04-23.