Centroid Algorithm

Utilities for finding peak in an image.

Author

Mihai Cara (for help, contact HST Help Desk)

License

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. When xmax and ymax are both None, 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 when xmax and ymax are provided but when one suspects that these input coordinates may not be very accurate by specifying an expanded brute-force search box through parameter peak_search_box.

Parameters
image_datanumpy.ndarray

Image data.

xmaxfloat, None, optional

Initial guess of the x-coordinate of the peak. When both xmax and ymax are None, 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 entire image_data array, regardless of the value of peak_search_box parameter.

ymaxfloat, None, optional

Initial guess of the x-coordinate of the peak. When both xmax and ymax are None, 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 entire image_data array, regardless of the value of peak_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 and ymax) 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 by peak_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 and ymax) 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 input xmax and ymax. If a single integer number is provided, then it is assumed that search box is a square with sides of length given by peak_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' or None turns off brute-force search of the maximum. When peak_search_box is 'all' then the entire image_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 as peak_fit_box.

Note

This parameter is ignored when both xmax and ymax are None 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 in image_data will be used for fitting.

Returns
coordtuple of float

A pair of coordinates of the peak.