playnano.processing.filters module

Module for applying flattening and filtering to AFM images in Numpy arrays.

playnano.processing.filters.gaussian_filter(data: ndarray, sigma: float = 1.0) → ndarray[source]

Apply a Gaussian low-pass filter to smooth high-frequency noise.

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

  • sigma (float) – Standard deviation for Gaussian kernel, in pixels.

Returns:

Smoothed image.

Return type:

np.ndarray

playnano.processing.filters.polynomial_flatten(data: ndarray, order: int = 2) → ndarray[source]

Subtract a 2D polynomial surface of given order to flatten AFM image data.

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

  • order (int) – Polynomial order for surface fitting (e.g., 1 for linear, 2 for quadratic).

Returns:

Flattened image with polynomial background removed.

Return type:

np.ndarray

Raises:

ValueError – If data is not a 2D array, if order is not a positive integer, or if there are fewer finite pixels than polynomial terms.

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; before, terms were silently dropped and the background was not fully removed.

playnano.processing.filters.register_filters()[source]

Return list of filter options.

playnano.processing.filters.remove_plane(data: ndarray) → ndarray[source]

Fit a 2D plane to the image by least squares and subtract it.

Uses a 2D plane (z = ax + by + c) to remove overall tilt.

Parameters:

data (np.ndarray) – 2D AFM image data.

Returns:

Plane-removed image.

Return type:

np.ndarray

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.filters.row_median_align(data: ndarray) → ndarray[source]

Subtract the median of each row from that row to remove horizontal banding.

Parameters:

data (np.ndarray) – 2D AFM image data.

Returns:

Row-aligned image.

Return type:

np.ndarray

playnano.processing.filters.vertical_flip(data: ndarray) → ndarray[source]

Vertically flip an image, reversing the row order.

Parameters:

data (np.ndarray) – 2D AFM image data.

Returns:

Vertically flipped image.

Return type:

np.ndarray

playnano.processing.filters.zero_mean(data: ndarray) → ndarray[source]

Subtract the overall mean height to center data around zero.

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

  • mask (np.ndarray, optional) – Boolean mask of same shape as data; True indicates region to exclude from mean.

Returns:

Zero-mean image.

Return type:

np.ndarray

playnano.processing.filters.zero_median(data: ndarray) → ndarray[source]

Subtract the overall median height to center the background around zero.

Parameters:

data (np.ndarray) – 2D AFM image data.

Returns:

Zero-median image.

Return type:

np.ndarray