topostats.filters#

Contains filter functions that take a 2D array representing an image as an input, as well as necessary parameters, and return a 2D array of the same size representing the filtered image.

Attributes#

Classes#

Filters

Class for filtering scans.

Module Contents#

topostats.filters.LOGGER#
class topostats.filters.Filters(image: numpy.ndarray, filename: str, pixel_to_nm_scaling: float, row_alignment_quantile: float = 0.5, threshold_method: str = 'otsu', otsu_threshold_multiplier: float = 1.7, threshold_std_dev: dict = None, threshold_absolute: dict = None, gaussian_size: float = None, gaussian_mode: str = 'nearest', remove_scars: dict = None)[source]#

Class for filtering scans.

filename#
pixel_to_nm_scaling#
gaussian_size#
gaussian_mode#
row_alignment_quantile#
threshold_method#
otsu_threshold_multiplier#
threshold_std_dev#
threshold_absolute#
remove_scars_config#
images#
thresholds = None#
medians#
results#
median_flatten(image: numpy.ndarray, mask: numpy.ndarray = None, row_alignment_quantile: float = 0.5) numpy.ndarray[source]#

Uses the method of median differences to flatten the rows of an image, aligning the rows and centering the median around zero. When used with a mask, this has the effect of centering the background data on zero. Note this function does not handle scars.

Parameters:
  • image (np.ndarray) – 2-D image of the data to align the rows of.

  • mask (np.ndarray) – Boolean array of points to mask out (ignore).

  • row_alignment_quantile (float) – Quantile (0.0 to 1.0) used for defining the average background.

Returns:

Returns a copy of the input image with rows aligned

Return type:

np.ndarray

remove_tilt(image: numpy.ndarray, mask: numpy.ndarray = None)[source]#

Removes planar tilt from an image (linear in 2D space). It uses a linear fit of the medians of the rows and columns to determine the linear slants in x and y directions and then subtracts the fit from the columns.

Parameters:
  • image (np.ndarray) – 2-D image of the data to remove the planar tilt from.

  • mask (np.ndarray) – Boolean array of points to mask out (ignore).

  • img_name (str) – Name of the image (to be able to print information in the console).

Returns:

Returns a copy of the input image with the planar tilt removed

Return type:

np.ndarray

remove_quadratic(image: numpy.ndarray, mask: numpy.ndarray = None)[source]#

Removes the quadratic bowing that can be seen in some large-scale AFM images. It uses a simple quadratic fit on the medians of the columns of the image and then subtracts the calculated quadratic from the columns.

Parameters:
  • image (np.ndarray) – 2-D image of the data to remove the quadratic from.

  • mask (np.ndarray) – Boolean array of points to mask out (ignore).

Returns:

Returns a copy of the input image with the quadratic bowing removed

Return type:

np.ndarray

static calc_diff(array: numpy.ndarray) numpy.ndarray[source]#

Calculate the difference of an array.

calc_gradient(array: numpy.ndarray, shape: int) numpy.ndarray[source]#

Calculate the gradient of an array.

average_background(image: numpy.ndarray, mask: numpy.ndarray = None) numpy.ndarray[source]#

Zero the background by subtracting the non-masked mean from all pixels.

Parameters:
  • image (np.array) – Numpy array representing image.

  • mask (np.array) – Mask of the array, should have the same dimensions as image.

Returns:

Numpy array of image zero averaged.

Return type:

np.ndarray

gaussian_filter(image: numpy.ndarray, **kwargs) numpy.array[source]#

Apply Gaussian filter to an image.

Parameters:

image (np.array) – Numpy array representing image.

Returns:

Numpy array of gaussian blurred image.

Return type:

np.array

filter_image() None[source]#

Process a single image, filtering, finding grains and calculating their statistics.

Example

from topostats.io import LoadScan from topostats.topotracing import Filter, process_scan

filter = Filter(image=load_scan.image, … pixel_to_nm_scaling=load_scan.pixel_to_nm_scaling, … filename=load_scan.filename, … threshold_method=’otsu’) filter.filter_image()