radialcenter#

deeptrack.extras.radialcenter.radialcenter(I: Any, invert_xy: bool = False) tuple[float, float]#

Calculate the center of a 2D intensity distribution.

The method considers, for each half-pixel midpoint, a line passing through that point with slope parallel to the local intensity gradient. It then finds the point that minimizes a weighted sum of squared perpendicular distances to all such lines (weighted least squares).

Parameters#

I: Any

2D intensity distribution (e.g. a grayscale image). The input is converted to a NumPy array. Extra singleton dimensions are removed.

invert_xy: bool, optional

If True, return (y, x) instead of (x, y). Defaults to False.

Returns#

tuple[float, float]

The estimated center coordinate (x, y) in pixel units, where (0, 0) corresponds to the left/top-most pixel. The returned coordinates are floating-point and may fall between pixels. If the center cannot be estimated (e.g., constant image or singular system), returns (nan, nan) (or swapped if invert_xy=True).

Notes#

This function requires SciPy for the 2D convolution used to smooth derivatives.