Masking routines.

Functions:

mask_change_convention(mask[, ...])

Convert an array from one 'mask' convention to another.

masks_change_convention(masks[, ...])

Perform convention change of sequence of masks

labels_to_masks(labels[, features, ...])

Convert labels array to list of masks

masks_to_labels(masks[, features, ...])

Convert list of masks to labels

lnpy.core.mask.mask_change_convention(mask, convention_in='image', convention_out='masked')[source]#

Convert an array from one ‘mask’ convention to another.

Parameters:
  • masks (None or ndarray of bool) – Masking array.

  • convention_in, convention_out (string or bool) – Convention for input and output. Convention for mask. Allowable values are:

    • 'image' ``or ``True : True values included, False values excluded. This is the normal convention in scipy.ndimage.

    • 'masked' or False: False values are included, True values are excluded. This is the convention in numpy.ma

Returns:

ndarray – New ‘mask’ array with specified convention.

lnpy.core.mask.masks_change_convention(masks, convention_in='image', convention_out='masked')[source]#

Perform convention change of sequence of masks

Parameters:
  • masks (sequence of array-like) – masks[i] is the ‘ith’ mask

  • convention_in, convention_out (string or bool or None) – Convention for input and output. Convention for mask. Allowable values are:

    • ‘image’ or True : True values included, False values excluded. This is the normal convention in scipy.ndimage.

    • ‘masked’ or False: False values are included, True values are excluded. This is the convention in numpy.ma

    If None, then pass return input mask

Returns:

new_masks (list of ndarray) – New ‘masks’ array with specified convention.

lnpy.core.mask.labels_to_masks(labels, features=None, include_boundary=False, convention='image', check_features=True, **kwargs)[source]#

Convert labels array to list of masks

Parameters:
  • labels (ndarray of int) – Each unique value i in labels indicates a mask. That is labels == i.

  • features (sequence of int) – If specified, extract only those locations where labels == feature for all values feature in features. That is, select a subset of unique label values.

  • include_boundary (bool) – if True, include boundary regions in output mask

  • convention (string or bool) – Convention for mask. Allowable values are:

    • ‘image’ or TrueTrue values included, False values excluded.

      This is the normal convention in scipy.ndimage.

    • ‘masked’ or False: False values are included, True values are excluded.

      This is the convention in numpy.ma

  • check_features (bool) – if True, then make sure each feature is in labels

  • **kwargs – arguments to find_boundary if include_boundary is True default to mode=’outer’, connectivity=labels.ndim

Returns:

  • output (list of ndarray of bool) – list of mask arrays, each with same shape as labels, with mask convention convention.

  • features (list) – features

lnpy.core.mask.masks_to_labels(masks, features=None, convention='image', dtype=<class 'numpy.int64'>)[source]#

Convert list of masks to labels

Parameters:
  • masks (list of array-like of bool) – list of mask arrays.

  • features (sequence of int) – If specified, extract only those locations where labels == feature for all values feature in features. That is, select a subset of unique label values.

  • convention (string or bool) – Convention for mask. Allowable values are:

    • ‘image’ or TrueTrue values included, False values excluded.

      This is the normal convention in scipy.ndimage.

    • ‘masked’ or False: False values are included, True values are excluded.

      This is the convention in numpy.ma

Returns:

ndarray – Label array.

See also

labels_to_masks