topostats.filters ================= .. py:module:: topostats.filters .. autoapi-nested-parse:: 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. .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: topostats.filters.LOGGER Classes ------- .. autoapisummary:: topostats.filters.Filters Module Contents --------------- .. py:data:: LOGGER .. py:class:: Filters(image: numpy.ndarray, filename: str, pixel_to_nm_scaling: float, 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', quiet: bool = False) Class for filtering scans. .. !! processed by numpydoc !! .. py:attribute:: filename .. py:attribute:: pixel_to_nm_scaling .. py:attribute:: gaussian_size .. py:attribute:: gaussian_mode .. py:attribute:: threshold_method .. py:attribute:: otsu_threshold_multiplier .. py:attribute:: threshold_std_dev .. py:attribute:: threshold_absolute .. py:attribute:: images .. py:attribute:: thresholds :value: None .. py:attribute:: medians .. py:attribute:: results .. py:method:: median_flatten(image: numpy.ndarray, mask: numpy.ndarray = None, img_name: str = None) -> numpy.ndarray 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. :param image: 2-D image of the data to align the rows of. :type image: np.ndarray :param mask: Boolean array of points to mask out (ignore). :type mask: np.ndarray :param img_name: Name of the image (to be able to print information in the console). :type img_name: str :returns: Returns a copy of the input image with rows aligned :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: remove_tilt(image: numpy.ndarray, mask: numpy.ndarray = None, img_name: str = None) 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. :param image: 2-D image of the data to remove the planar tilt from. :type image: np.ndarray :param mask: Boolean array of points to mask out (ignore). :type mask: np.ndarray :param img_name: Name of the image (to be able to print information in the console). :type img_name: str :returns: Returns a copy of the input image with the planar tilt removed :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: remove_quadratic(image: numpy.ndarray, mask: numpy.ndarray = None, img_name: str = None) 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. :param image: 2-D image of the data to remove the quadratic from. :type image: np.ndarray :param mask: Boolean array of points to mask out (ignore). :type mask: np.ndarray :param img_name: Name of the image (to be able to print information in the console). :type img_name: str :returns: Returns a copy of the input image with the quadratic bowing removed :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: calc_diff(array: numpy.ndarray) -> numpy.ndarray :staticmethod: Calculate the difference of an array. .. !! processed by numpydoc !! .. py:method:: calc_gradient(array: numpy.ndarray, shape: int) -> numpy.ndarray Calculate the gradient of an array. .. !! processed by numpydoc !! .. py:method:: average_background(image: numpy.ndarray, mask: numpy.ndarray = None) -> numpy.ndarray Zero the background by subtracting the non-masked mean from all pixels. :param image: Numpy array representing image. :type image: np.array :param mask: Mask of the array, should have the same dimensions as image. :type mask: np.array :returns: Numpy array of image zero averaged. :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: gaussian_filter(image: numpy.ndarray, **kwargs) -> numpy.array Apply Gaussian filter to an image. :param image: Numpy array representing image. :type image: np.array :returns: Numpy array of gaussian blurred image. :rtype: np.array .. !! processed by numpydoc !! .. py:method:: filter_image() -> None Process a single image, filtering, finding grains and calculating their statistics. .. rubric:: Example from topostats.io import LoadScan from topostats.topotracing import Filter, process_scan load_scan = LoadScan("minicircle.spm", channel="Height") load_scan.get_data() 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() .. !! processed by numpydoc !!