playnano.processing.mask_generators module

Functions that make boolean masks of features in 2D AFM frames.

Each function takes a frame and returns a boolean array of the same shape, in which True marks foreground (features) and False marks background. In a ProcessingPipeline, masks made one after another are combined with logical OR until a clear step. Masked filters (playnano.processing.masked_filters) use the mask to leave features out of background fits.

playnano.processing.mask_generators.mask_adaptive(data: ndarray, block_size: int = 15, offset: float = 0.0) → ndarray[source]

Mask pixels above the mean of their local block.

The image is divided into non-overlapping square blocks of block_size pixels (smaller at the right and bottom edges), and each pixel is compared with the mean of its own block.

Parameters:
  • data (numpy.ndarray) – 2D AFM image.

  • block_size (int, optional) – Side length of each block, in pixels. Default is 15.

  • offset (float, optional) – Added to each block mean before comparing, in the units of data. Default is 0.0.

Returns:

Boolean mask, True where a pixel is greater than its block mean plus offset.

Return type:

numpy.ndarray

playnano.processing.mask_generators.mask_below_threshold(data: ndarray, threshold: float = 0.0) → ndarray[source]

Mask pixels lower than a threshold.

Parameters:
  • data (numpy.ndarray) – 2D AFM image.

  • threshold (float, optional) – Height threshold, in the units of data (usually nm). Default is 0.0.

Returns:

Boolean mask, True where data < threshold. NaN and infinite pixels are False.

Return type:

numpy.ndarray

playnano.processing.mask_generators.mask_mean_offset(data: ndarray, factor: float = 1.0) → ndarray[source]

Mask pixels more than factor standard deviations above the mean.

Parameters:
  • data (numpy.ndarray) – 2D AFM image.

  • factor (float, optional) – Number of standard deviations above the image mean at which pixels are masked. Default is 1.0.

Returns:

Boolean mask, True where data - mean(data) > factor * std(data).

Return type:

numpy.ndarray

playnano.processing.mask_generators.mask_morphological(data: ndarray, threshold: float = 0.0, structure_size: int = 3) → ndarray[source]

Mask pixels far from zero, then close small gaps with binary closing.

Unlike mask_threshold(), this uses the absolute height, so both features above threshold and holes below -threshold are masked.

Parameters:
  • data (numpy.ndarray) – 2D AFM image, normally already flattened so the background is near zero.

  • threshold (float, optional) – Pixels with abs(data) > threshold are masked before closing. Default is 0.0, which masks every pixel that is not exactly zero.

  • structure_size (int, optional) – Side length, in pixels, of the square structuring element used for closing. Default is 3.

Returns:

Boolean mask after closing.

Return type:

numpy.ndarray

See also

scipy.ndimage.binary_closing

The closing operation used.

playnano.processing.mask_generators.mask_threshold(data: ndarray, threshold: float = 0.0) → ndarray[source]

Mask pixels higher than a threshold.

Parameters:
  • data (numpy.ndarray) – 2D AFM image.

  • threshold (float, optional) – Height threshold, in the units of data (usually nm). Default is 0.0.

Returns:

Boolean mask, True where data > threshold. NaN and infinite pixels are False.

Return type:

numpy.ndarray

playnano.processing.mask_generators.register_masking()[source]

Return the built-in mask functions.

Returns:

Maps each step name (str) to its function, for example "mask_threshold" to mask_threshold().

Return type:

dict