Skip to content

Thresholds Modules

Functions for calculating thresholds.

threshold(image: npt.NDArray, method: str = None, otsu_threshold_multiplier: float = None, **kwargs: dict) -> float

Thresholding for producing masks.

Parameters:

Name Type Description Default
image NDArray

2-D Numpy array of image for thresholding.

required
method str

Method to use for thresholding, currently supported methods are otsu (default), mean and minimum.

None
otsu_threshold_multiplier float

Factor for scaling the Otsu threshold.

None
**kwargs dict

Additional keyword arguments to pass to skimage methods.

{}

Returns:

Type Description
float

Threshold of image using specified method.

Source code in topostats\thresholds.py
def threshold(image: npt.NDArray, method: str = None, otsu_threshold_multiplier: float = None, **kwargs: dict) -> float:
    """
    Thresholding for producing masks.

    Parameters
    ----------
    image : npt.NDArray
        2-D Numpy array of image for thresholding.
    method : str
        Method to use for thresholding, currently supported methods are otsu (default), mean and minimum.
    otsu_threshold_multiplier : float
        Factor for scaling the Otsu threshold.
    **kwargs : dict
        Additional keyword arguments to pass to skimage methods.

    Returns
    -------
    float
        Threshold of image using specified method.
    """
    thresholder = _get_threshold(method)
    return thresholder(image, otsu_threshold_multiplier=otsu_threshold_multiplier, **kwargs)