topostats.thresholds#

Functions for calculating thresholds.

Module Contents#

Functions#

threshold(→ float)

Thresholding for producing masks.

_get_threshold(→ collections.abc.Callable)

Creator component which determines which threshold method to use.

_threshold_otsu(→ float)

Calculate the Otsu threshold.

_threshold_mean(→ float)

Calculate the Mean threshold.

_threshold_minimum(→ float)

Calculate the Minimum threshold.

_threshold_yen(→ float)

Calculate the Yen threshold.

_threshold_triangle(→ float)

Calculate the triangle threshold.

Attributes#

LOGGER

topostats.thresholds.LOGGER#
topostats.thresholds.threshold(image: numpy.typing.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:

Threshold of image using specified method.

Return type:

float

topostats.thresholds._get_threshold(method: str = 'otsu') collections.abc.Callable#

Creator component which determines which threshold method to use.

Parameters:

method (str) – Threshold method to use, currently supports otsu (default), mean, minimum, mean yen, and triangle.

Returns:

Returns function appropriate for the required threshold method.

Return type:

function

Raises:

ValueError – Unsupported methods result in ValueError.

topostats.thresholds._threshold_otsu(image: numpy.typing.NDArray, otsu_threshold_multiplier: float = None, **kwargs) float#

Calculate the Otsu threshold.

For more information see skimage.filters.threshold_otsu().

Parameters:
  • image (npt.NDArray) – 2-D Numpy array of image for thresholding.

  • otsu_threshold_multiplier (float) – Factor for scaling Otsu threshold.

  • **kwargs (dict) – Dictionary of keyword arguments to pass to ‘skimage.filters.threshold_otsu(**kwargs)’.

Returns:

Threshold to be used in masking heights.

Return type:

float

topostats.thresholds._threshold_mean(image: numpy.typing.NDArray, otsu_threshold_multiplier: float = None, **kwargs) float#

Calculate the Mean threshold.

For more information see skimage.filters.threshold_mean().

Parameters:
  • image (npt.NDArray) – 2-D Numpy array of image for thresholding.

  • otsu_threshold_multiplier (float) – Factor for scaling (not used).

  • **kwargs (dict) – Dictionary of keyword arguments to pass to ‘skimage.filters.threshold_mean(**kwargs)’.

Returns:

Threshold to be used in masking heights.

Return type:

float

topostats.thresholds._threshold_minimum(image: numpy.typing.NDArray, otsu_threshold_multiplier: float = None, **kwargs) float#

Calculate the Minimum threshold.

For more information see skimage.filters.threshold_minimum().

Parameters:
  • image (npt.NDArray) – 2-D Numpy array of image for thresholding.

  • otsu_threshold_multiplier (float) – Factor for scaling (not used).

  • **kwargs (dict) – Dictionary of keyword arguments to pass to ‘skimage.filters.threshold_minimum(**kwargs)’.

Returns:

Threshold to be used in masking heights.

Return type:

float

topostats.thresholds._threshold_yen(image: numpy.typing.NDArray, otsu_threshold_multiplier: float = None, **kwargs) float#

Calculate the Yen threshold.

For more information see skimage.filters.threshold_yen().

Parameters:
  • image (npt.NDArray) – 2-D Numpy array of image for thresholding.

  • otsu_threshold_multiplier (float) – Factor for scaling (not used).

  • **kwargs (dict) – Dictionary of keyword arguments to pass to ‘skimage.filters.threshold_yen(**kwargs)’.

Returns:

Threshold to be used in masking heights.

Return type:

float

topostats.thresholds._threshold_triangle(image: numpy.typing.NDArray, otsu_threshold_multiplier: float = None, **kwargs) float#

Calculate the triangle threshold.

For more information see skimage.filters.threshold_triangle().

Parameters:
  • image (npt.NDArray) – 2-D Numpy array of image for thresholding.

  • otsu_threshold_multiplier (float) – Factor for scaling (not used).

  • **kwargs (dict) – Dictionary of keyword arguments to pass to ‘skimage.filters.threshold_triangle(**kwargs)’.

Returns:

Threshold to be used in masking heights.

Return type:

float