Slicer
Module for slicing two-dimensional arrays to three-dimensional arrays of stacked masks.
calculate_region_properties(array, spacing)
Calculate the region properties on a segmented array.
The arrays can be either individual slices from a three-dimensional image or the full three-dimensional array
itself. If the later then the resulting attribute area will be a "volume". By including the spacing
argument, which should be the pixel_to_nm_scaling attribute of the AFMSlicer object the area/volume is
in the actual units measured rather than pixels.
Parameters
array : npt.NDArray Array of labelled regions. spacing : float Pixel to nm scaling.
Returns
list[RegionProperties]
A list of RegionProperties.
Source code in src/afmslicer/slicer.py
mask_slices(stacked_array, slices=None, layers=None, min_height=None, max_height=None)
Convert a three-dimensional sliced array into masks based.
A three-dimensional array is converted to masked layers where each layer indicates whether a position in the two-dimensional cross-section is above the threshold for that layer. Thresholds are determined from the data itself if not explicitly provided.
Parameters
stacked_array : npt.NDArray Three-dimensional numpy array of image heights, each layer should be a copy of the original. slices : int, optional Number of slices to mask. Determined directly from data if not provided (i.e. depth of three-dimensional array). layers : npt.NDArray, optional Array of height thresholds for each slice. Determined directly from data if not provided. min_height : np.float64, optional Minimum height. Determined directly from data if not provided. max_height : np.float64, optional Maximum height. Determined directly from data if not provided.
Returns
npt.NDArray[bool] Three-dimensional array of masks.
Source code in src/afmslicer/slicer.py
mask_small_artefacts(labelled_array, properties, minimum_size)
Mask labelled features that are less than a specified size from two-dimensional array.
Parameters
labelled_array : npt.NDArray[np.int32] A three-dimensional array with labelled regions. properties : dict[int, Any] The properties of labelled objects for each layer. minimum_size : float Minimum size below which labelled regions are removed.
Returns
npt.NDArray[np.int32]
Masked array with labelled regions smaller than minimum_size masked.
Source code in src/afmslicer/slicer.py
mask_small_artefacts_all_layers(labelled_array, properties, minimum_size)
Mask labelled features that are less than a specified size from three-dimensional array.
Parameters
labelled_array : npt.NDArray[np.int32] A three-dimensional array with labelled regions. properties : dict[int, Any] The properties of labelled objects for each layer. minimum_size : float Minimum size below which labelled regions are removed.
Returns
npt.NDArray[np.int32]
Masked array with labelled regions smaller than minimum_size masked.
Source code in src/afmslicer/slicer.py
region_properties_by_slices(array, spacing)
Calculate region properties for each layer in a three-dimensinoal sliced array.
Parameters
array : npt.NDArray[np.int32] Three-dimensional sliced and labelled array. spacing : float Pixel to nanometer scaling.
Returns
dict[int, Any]
Dictionary of regionprops calculated using skimage.
Source code in src/afmslicer/slicer.py
segment(array, method='label', tidy_border=True, **kwargs)
Segment an array.
Parameters
array : npt.NDArray
Two-dimensional numpy array to segment.
method : str, optional
Segmentation method, supports the label (default) and watershed methods implemented by Scikit Image.
tidy_border : bool
Whether to remove objects that straddle the border of the image.
**kwargs : dict[str, Any], optional
Additional arguments to pass for segmentation.
Returns
npt.NDArray Labelled array of objects.
Source code in src/afmslicer/slicer.py
segment_slices(array, method='label', tidy_border=False)
Segment individual layers of a three-dimensional numpy array.
Parameters
array : npt.NDArray[np.bool]
Three-dimensional boolean array to be segmented.
method : str
Sgementation method to use. Currne options are label (default) and watershed.
tidy_border : bool
Whether to tidy the border.
Returns
npt.NDArray[np.bool] Three-dimensional array of labelled layers.
Source code in src/afmslicer/slicer.py
show_layers(array)
Helper function for debugging which shows individual layers of a three-dimensional numpy array.
Parameters
array : npt.NDArray Three-dimensional numpy array.
Source code in src/afmslicer/slicer.py
slicer(heights, slices)
Convert a two-dimensional array to a three-dimensional stacked array with copies of the original in each layer.
Parameters
heights : npt.NDArray[np.float64] Two-dimensional numpy array of heights. slices : int Number of slices to make.
Returns
npt.NDArray[np.float64]
Expanded numpy array with the original two-dimensional array copied slices in the third dimension.
Examples
import numpy as np simple = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) slicer(heights=simple, slices=2) array([[[1, 1], [2, 2], [3, 3]],
[[4, 4], [5, 5], [6, 6]],
[[7, 7], [8, 8], [9, 9]]])