playnano.processing.masked_filters module¶
2D filters that fit or measure the background only, using a boolean mask.
Each function takes a frame and a mask of the same shape, in which True marks
foreground (features) and False marks background. The statistic or fit is
computed from background pixels and then applied to the whole frame. The
ProcessingPipeline uses these in place of
the filters in playnano.processing.filters when a mask is active.
- playnano.processing.masked_filters.polynomial_flatten_masked(data: ndarray, mask: ndarray, order: int = 2) ndarray[source]¶
Fit a 2D polynomial to the background pixels and subtract it from the whole image.
- Parameters:
data (numpy.ndarray) – 2D AFM image.
mask (numpy.ndarray) – Boolean array with the same shape as
data. True marks foreground pixels, which are left out of the fit; False marks background.order (int, optional) – Total order of the polynomial: 1 is a plane, 2 is quadratic. Default is 2.
- Returns:
Image with the polynomial background removed, as float64.
- Return type:
- Raises:
ValueError – If
maskanddatahave different shapes,orderis not a positive integer, or fewer background pixels are finite than the polynomial has terms.RuntimeError – If the least-squares fit fails.
Notes
NaN and infinite pixels are left out of the fit and stay NaN or infinite in the output. Version 0.2.0 scales x and y to [-1, 1] before fitting, so orders of 3 and above fit correctly on large frames.
- playnano.processing.masked_filters.register_mask_filters()[source]¶
Return the masked filters, keyed by the name of the unmasked filter they replace.
- Returns:
Maps each step name (str) to its function, for example
"remove_plane"toremove_plane_masked().- Return type:
- playnano.processing.masked_filters.remove_plane_masked(data: ndarray, mask: ndarray) ndarray[source]¶
Fit a plane to the background pixels and subtract it from the whole image.
- Parameters:
data (numpy.ndarray) – 2D AFM image.
mask (numpy.ndarray) – Boolean array with the same shape as
data. True marks foreground pixels, which are left out of the fit; False marks background.
- Returns:
Image with the plane removed, as float64.
- Return type:
- Raises:
ValueError – If
maskanddatahave different shapes, or fewer than 3 background pixels are finite.
Notes
NaN and infinite pixels are left out of the fit and stay NaN or infinite in the output. Version 0.1.1 fits with NumPy instead of scikit-learn (same result) and handles NaN pixels instead of raising.
- playnano.processing.masked_filters.row_median_align_masked(data: ndarray, mask: ndarray) ndarray[source]¶
Subtract from each row the median of its background pixels.
- Parameters:
data (numpy.ndarray) – 2D AFM image.
mask (numpy.ndarray) – Boolean array with the same shape as
data. True marks foreground pixels, which are left out of the fit; False marks background.
- Returns:
Row-aligned image, as float64. Rows with no background pixels are left unchanged.
- Return type:
- Raises:
ValueError – If
maskanddatahave different shapes.
- playnano.processing.masked_filters.zero_mean_masked(data: ndarray, mask: ndarray = None) ndarray[source]¶
Subtract the mean height of the background so it is centred on zero.
- Parameters:
data (numpy.ndarray) – 2D AFM image.
mask (numpy.ndarray, optional) – Boolean array with the same shape as
data. True marks foreground pixels, which are left out of the mean. If None, the mean of the whole image is used and a warning is logged.
- Returns:
Zero-mean image, as float64.
- Return type:
- Raises:
ValueError – If
maskanddatahave different shapes, or every pixel is masked.
- playnano.processing.masked_filters.zero_median_masked(data: ndarray, mask: ndarray = None) ndarray[source]¶
Subtract the median height of the background so it is centred on zero.
- Parameters:
data (numpy.ndarray) – 2D AFM image.
mask (numpy.ndarray, optional) – Boolean array with the same shape as
data. True marks foreground pixels, which are left out of the median. If None, the median of the whole image is used and a warning is logged.
- Returns:
Zero-median image, as float64.
- Return type:
- Raises:
ValueError – If
maskanddatahave different shapes, or every pixel is masked.