machinevisiontoolbox.Image.peak2d
- Image.peak2d(npeaks=2, scale=1, interp=False, positive=True)
Find local maxima in image
- Parameters:
npeaks (int, optional) – number of peaks to return, defaults to 2
scale (int) – scale of peaks to consider
interp (bool, optional) – interpolate the peak positions, defaults to False
positive (bool, optional) – only select peaks that are positive, defaults to False
- Returns:
peak magnitude and positions
- Return type:
ndarray(npeaks), ndarray(2,npeaks)
Find the positions of the local maxima in the image. A local maxima is the largest value within a sliding window of width \(2 \mathtt{scale}+1\).
Example:
>>> from machinevisiontoolbox import Image >>> import numpy as np >>> peak = np.array([[10, 20, 30], [40, 50, 45], [15, 20, 30]]) >>> img = Image(np.pad(peak, 3, constant_values=10)) >>> img.A array([[10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 20, 30, 10, 10, 10], [10, 10, 10, 40, 50, 45, 10, 10, 10], [10, 10, 10, 15, 20, 30, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10]]) >>> img.peak2d(interp=True) (array([7.5]), array([[4.1667], [4. ]]))
- Note:
Edges elements will never be returned as maxima.
To find minima, use
peak2d(-image)
.The
interp
option fits points in the neighbourhood about the peak with a paraboloid and its peak position is returned.
- Seealso: