Centroid Algorithm¶
Utilities for finding peak in an image.
- Author
Mihai Cara (for help, contact HST Help Desk)
- License
-
subpixal.centroid.
find_peak
(image_data, xmax=None, ymax=None, peak_fit_box=5, peak_search_box=None, mask=None)[source]¶ Find location of the peak in an array. This is done by fitting a second degree 2D polynomial to the data within a
peak_fit_box
and computing the location of its maximum. Whenxmax
andymax
are bothNone
, an initial estimate of the position of the maximum will be performed by searching for the location of the pixel/array element with the maximum value. This kind of initial brute-force search can be performed even whenxmax
andymax
are provided but when one suspects that these input coordinates may not be very accurate by specifying an expanded brute-force search box through parameterpeak_search_box
.- Parameters
- image_datanumpy.ndarray
Image data.
- xmaxfloat, None, optional
Initial guess of the x-coordinate of the peak. When both
xmax
andymax
areNone
, the initial (pre-fit) estimate of the location of the peak will be obtained by a brute-force search for the location of the maximum-value pixel in the entireimage_data
array, regardless of the value ofpeak_search_box
parameter.- ymaxfloat, None, optional
Initial guess of the x-coordinate of the peak. When both
xmax
andymax
areNone
, the initial (pre-fit) estimate of the location of the peak will be obtained by a brute-force search for the location of the maximum-value pixel in the entireimage_data
array, regardless of the value ofpeak_search_box
parameter.- peak_fit_boxint, tuple of int, optional
Size (in pixels) of the box around the input estimate of the maximum (given by
xmax
andymax
) to be used for quadratic fitting from which peak location is computed. If a single integer number is provided, then it is assumed that fitting box is a square with sides of length given bypeak_fit_box
. If a tuple of two values is provided, then first value indicates the width of the box and the second value indicates the height of the box.- peak_search_boxstr {‘all’, ‘off’, ‘fitbox’}, int, tuple of int, None,optional
Size (in pixels) of the box around the input estimate of the maximum (given by
xmax
andymax
) to be used for brute-force search of the maximum value pixel. This search is performed before quadratic fitting in order to improve the original estimate of the peak given by inputxmax
andymax
. If a single integer number is provided, then it is assumed that search box is a square with sides of length given bypeak_fit_box
. If a tuple of two values is provided, then first value indicates the width of the box and the second value indicates the height of the box.'off'
orNone
turns off brute-force search of the maximum. Whenpeak_search_box
is'all'
then the entireimage_data
data array is searched for maximum and when it is set to'fitbox'
then the brute-force search is performed in the same box aspeak_fit_box
.Note
This parameter is ignored when both
xmax
andymax
areNone
since in that case the brute-force search for the maximum is performed in the entire input array.- masknumpy.ndarray, optional
A boolean type
ndarray
indicating “good” pixels in image data (True
) and “bad” pixels (False
). If not provided all pixels inimage_data
will be used for fitting.
- Returns
- coordtuple of float
A pair of coordinates of the peak.