def bounding_box(alpha, threshold=0.1):
    """
    Returns a bounding box of the support.

    Parameters
    ----------
    alpha : ndarray, ndim=2
        Any one-channel image where the background has zero or low intensity.
    threshold : float
        The threshold that divides background from foreground.

    Returns
    -------
    bounding_box : (top, left, bottom, right)
        The bounding box describing the smallest rectangle containing the
        foreground object, as defined by the threshold.
    """
    assert alpha.ndim == 2

    # Take the bounding box of the support, with a certain threshold.
    supp_axs = [alpha.max(axis=1-i) for i in range(2)]

    # Check first and last value of that threshold
    bb = [np.where(supp_axs[i] > threshold)[0][[0, -1]] for i in range(2)]

    return (bb[0][0], bb[1][0], bb[0][1], bb[1][1])
def bounding_box ( alpha , threshold = 0.1 ) : assert alpha . ndim == 2 supp_axs = [ alpha . max ( axis = 1 - i ) for i in range ( 2 ) ] bb = [ np . where ( supp_axs [ i ] > threshold ) [ 0 ] [ [ 0 , - 1 ] ] for i in range ( 2 ) ] return ( bb [ 0 ] [ 0 ] , bb [ 1 ] [ 0 ] , bb [ 0 ] [ 1 ] , bb [ 1 ] [ 1 ] )
Returns a bounding box of the support.

    Parameters
    ----------
    alpha : ndarray, ndim=2
        Any one-channel image where the background has zero or low intensity.
    threshold : float
        The threshold that divides background from foreground.

    Returns
    -------
    bounding_box : (top, left, bottom, right)
        The bounding box describing the smallest rectangle containing the
        foreground object, as defined by the threshold.