Image feature classes
Whole image features
- 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:
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:
- 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, *args, **kwargs)[source]
Plot Hough lines
- Parameters:
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.
- 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 ofskip
). This is helpful for pedagogy but very inefficient in practice.- Seealso:
- 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:
Point features
Create set of SIFT point features |
|
Create set of ORB point features |
|
Create set of BRISK point features |
|
Create set of AKAZE point features |
|
Create set of FREAK point features |
|
Create set of BOOST point features |
|
Create set of BRIEF point features |
|
Create set of DAISY point features |
|
Create set of LATCH point features |
|
Create set of LUCID point features |
|
Create set of Harris corner features |