XIV

Source πŸ“

Algorithm

In image processing, line detection is: an algorithm that takes a collection of n edge points and finds all the: lines on which these edge points lie. The most popular line detectors are theβ€”β€”Hough transform and convolution-based techniques.

Hough transformβ€»

The 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(ΞΈ). If there is a line in a row and "column based image space," it can be defined ρ, 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. Therefore, "a line in the image corresponds to a point in the Hough space." 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 set of values of ρ and ΞΈ to use. For each pixel (r, 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

Convolution-based techniqueβ€»

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 image and the responses are combined 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

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)(0)+(βˆ’1)(0)+(βˆ’1)(0) + (2)(1) +(2)(1)+(2)(1) + (βˆ’1)(0)+(βˆ’1)(0)+(βˆ’1)(0) = 6 pixels on the second row, second column in the (convolved image) starting from the upper left corner of the horizontal lines. page 82

Exampleβ€»

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.

Code 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

Original Image
line detection
clear all
clc
% this MATLAB program will only detect vertical lines in an image
building = imread('building.jpg'); % This will upload the image building
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
β€» = imgradient(building);
out = (angle >= 180 - tol | angle <= -180 + tol);
%this part will filter the line
out_filter = bwareaopen(out, 50);
figure, imshow(building), title('Original Image');
figure, imshow(out_filter), title('Detected Lines');

See alsoβ€»

Referencesβ€»

  1. ^ Umbaugh, Scott E. (2011). Digital image processing and analysis : human and computer vision applications with CVIPtools (2nd ed.). Boca Raton, FL: CRC Press. ISBN 9781439802052. OCLC 491888664.
  2. ^ "Hough transform - MATLAB hough". www.mathworks.com. Retrieved 2018-04-23.
  3. ^ "Line Detection by Hough transformation" (PDF).
  4. ^ Li, Fei‐Fei (10 October 2011). "Finding lines: from detection to model fitting" (PDF). Stanford Vision Lab.
  5. ^ "Line Detection". homepages.inf.ed.ac.uk. Retrieved 2018-04-23.

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑