Line features

These methods extract features such as histograms and moments from grey-scale or color images.

class machinevisiontoolbox.ImageLineFeatures.ImageLineFeaturesMixin[source]

Line features are common in in many human-built environments.

Hough(**kwargs)[source]

Find Hough line features

Returns

Hough lines

Return type

Hough

Compute the Hough transform of the image and return an object that represents the lines found within the image.

Seealso

Hough

Supporting classes

class machinevisiontoolbox.ImageLineFeatures.Hough(image, ntheta=180, drho=1)[source]

Hough line features

Parameters
  • image (Image) – greyscale image

  • ntheta (int, optional) – number of steps in the theta direction, defaults to 180

  • drho (int, optional) – increment size in the rho direction, defaults to 1

Create a Hough line feature object. It can be used to detect:

  • lines using the classical Hough algorithm lines

  • line segments using the probabilistic Hough algorith lines_p

The Hough accumulator is a 2D array that counts votes for lines

\[u \cos \theta + v \sin \theta = \rho\]

with quantized parameters \(\theta\) and \(\rho\). The parameter \(\theta\) is quantized into ntheta steps spanning the interval \([-\pi, \pi)\), while \(\rho\) is quantized into steps of drho spanning the vertical dimension of the image.

Note

Lines are not detected until lines or lines_p is called. This instance simply holds parameters.

Reference
  • Robotics, Vision & Control for Python, Section 12.2, P. Corke, Springer 2023.

Seealso

lines lines_p

lines(minvotes)[source]

Get Hough lines

Parameters

minvotes (int) – only return lines with at least this many votes

Returns

Hough lines, one per row as \((\theta, \rho)\)

Return type

ndarray(n,2)

Return a set of lines that have at least minvotes of support. Each line is described by \((\theta, \rho)\) such that

\[u \cos \theta + v \sin \theta = \rho\]
Seealso

plot_lines lines_p

lines_p(minvotes, minlinelength=30, maxlinegap=10, seed=None)[source]

Get probabilistic Hough lines

Parameters
  • minvotes (int) – only return lines with at least this many votes

  • minlinelength (int) – minimum line length. Line segments shorter than that are rejected.

  • maxlinegap (int) – maximum allowed gap between points on the same line to link them.

Returns

Hough lines, one per row as \((u_1, v_1, u_2, v_2)\)

Return type

ndarray(n,4)

Return a set of line segments that have at least minvotes of support. Each line segment is described by its end points \((u_1, v_1)\) and \((u_2, v_2)\).

Seealso

plot_lines_p lines

plot_lines(lines, *args, **kwargs)[source]

Plot Hough lines

Parameters
  • lines (ndarray(n,2), ndarray(n,4)) – Hough or probabilistic Hough lines

  • args – positional arguments passed to Matplotlib plot

  • kwargs – arguments passed to Matplotlib plot

Detected lines are given as rows of lines:

  • for Hough lines, each row is \((\theta, \rho)\), and lines are clipped by the bounds of the current plot.

  • for probabilistic Hough lines, each row is \((u_1, v_1, u_2, v_2)\), and lines segments are drawn on the current plot.

Seealso

lines lines_p

accumulator(skip=1)[source]

Compute the Hough accumulator

Parameters

skip (int, optional) – increment for line strength threshold, defaults to 1

It creates two new attributes for the instance:

  • A which is the Hough “accumulator” array, rows represent \(\rho\) and columns represent \(\theta\).

  • votes is a list of the number of lines found versus threshold, it can be used to select an optimal threshold.

  • extent is \([\theta_{\mbox{min}}, \theta_{\mbox{max}}, \rho_{\mbox{min}}, \rho_{\mbox{max}}]\).

Warning

The OpenCV HoughLines function does not expose the accumulator array. This method “reverse engineers” the accumulator array through a costly process of computing the Hough transform for all possible thresholds (increasing in steps of skip). This is helpful for pedagogy but very inefficient in practice.

Seealso

plot_accumulator

plot_accumulator(**kwargs)[source]

Plot the Hough accumulator array

Parameters

kwargs – options passed to imshow

The Hough accumulator is computed, if not already existing, and the displayed as an image where brightness is proportional to the number of votes for that \((\theta, \rho)\) coordinate.

Seealso

accumulator