Image feature classes

Whole image features

machinevisiontoolbox.ImageWholeFeatures.Histogram(h, x)

class machinevisiontoolbox.ImageWholeFeatures.Histogram(h, x, isfloat=False)[source]
property x

Histogram bin values

Returns:

array of left-hand bin values

Return type:

ndarray(N)

Bin \(i\) contains grey values in the range \([x_{[i]}, x_{[i+1]})\).

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> hist = Image.Read('flowers1.png').hist()
>>> with np.printoptions(threshold=10):
...     hist.x
... 
array([  0.,   1.,   2., ..., 253., 254., 255.])
property h

Histogram count values

Returns:

array of histogram count values

Return type:

ndarray(N) or ndarray(N,P)

For a greyscale image this is a 1D array, for a multiplane (color) image this is a 2D array with the histograms of each plane as columns.

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> hist = Image.Read('flowers1.png').hist()
>>> with np.printoptions(threshold=10):
...     hist.h
... 
array([[ 388.,    2.,  546.],
       [ 443.,    2.,  596.],
       [ 555.,    2.,  610.],
       ...,
       [1003.,  186.,  407.],
       [1284.,  324.,  487.],
       [   0.,    0.,    0.]], dtype=float32)
property cdf

Cumulative histogram values

Returns:

array of cumulative histogram count values

Return type:

ndarray(N) or ndarray(N,P)

For a greyscale image this is a 1D array, for a multiplane (color) image this is a 2D array with the cumulative histograms of each plane as columns.

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> hist = Image.Read('flowers1.png').hist()
>>> with np.printoptions(threshold=10):
...     hist.cdf
... 
array([[   388.,      2.,    546.],
       [   831.,      4.,   1142.],
       [  1386.,      6.,   1752.],
       ...,
       [266651., 269436., 269391.],
       [267935., 269760., 269878.],
       [267935., 269760., 269878.]], dtype=float32)
property ncdf

Normalized cumulative histogram values

Returns:

array of normalized cumulative histogram count values

Return type:

ndarray(N) or ndarray(N,P)

For a greyscale image this is a 1D array, for a multiplane (color) image this is a 2D array with the normalized cumulative histograms of each plane as columns.

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> hist = Image.Read('flowers1.png').hist()
>>> with np.printoptions(threshold=10):
...     hist.ncdf
... 
array([[0.0014, 0.    , 0.002 ],
       [0.0031, 0.    , 0.0042],
       [0.0052, 0.    , 0.0065],
       ...,
       [0.9952, 0.9988, 0.9982],
       [1.    , 1.    , 1.    ],
       [1.    , 1.    , 1.    ]], dtype=float32)
plot(type='frequency', block=False, bar=None, style='stack', alpha=0.5, **kwargs)[source]

Plot histogram

Parameters:
  • type (str, optional) – histogram type, one of: ‘frequency’ [default], ‘cdf’, ‘ncdf’

  • block (bool, optional) – hold plot, defaults to False

  • bar (bool, optional) – histogram bar plot, defaults to True for frequency plot, False for other plots

  • style (str, optional) – Style for multiple plots, one of: ‘stack’ [default], ‘overlay’

  • alpha (float, optional) – transparency for overlay plot, defaults to 0.5

Raises:
  • ValueError – invalid histogram type

  • ValueError – cannot use overlay style for 1-channel histogram

peaks(**kwargs)[source]

Histogram peaks

Parameters:

kwargs – parameters passed to findpeaks

Returns:

positions of histogram peaks

Return type:

ndarray(M), list of ndarray

For a greyscale image return an array of grey values corresponding to local maxima. For a color image return a list of arrays of grey values corresponding to local maxima in each plane.

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> hist = Image.Read('street.png').hist()
>>> hist.peaks(scale=20)
array([ 40., 197., 153.])
Seealso:

findpeaks

Line features

class machinevisiontoolbox.ImageLineFeatures.HoughFeature(image, ntheta=180, drho=1)[source]
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 opencv.HoughLines

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 lines opencv.HoughLinesP

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

Point features

Inheritance diagram of machinevisiontoolbox.ImagePointFeatures.SIFTFeature, ImagePointFeatures.ORBFeature, ImagePointFeatures.BRISKFeature, ImagePointFeatures.AKAZEFeature, ImagePointFeatures.HarrisFeature, ImagePointFeatures.FREAKFeature, ImagePointFeatures.BOOSTFeature, ImagePointFeatures.BRIEFFeature, ImagePointFeatures.LATCHFeature, ImagePointFeatures.LUCIDFeature

SIFTFeature

Create set of SIFT point features

ORBFeature

Create set of ORB point features

BRISKFeature

Create set of BRISK point features

AKAZEFeature

Create set of AKAZE point features

FREAKFeature

Create set of FREAK point features

BOOSTFeature

Create set of BOOST point features

BRIEFFeature

Create set of BRIEF point features

DAISYFeature

Create set of DAISY point features

LATCHFeature

Create set of LATCH point features

LUCIDFeature

Create set of LUCID point features

HarrisFeature

Create set of Harris corner features