afmslicer.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:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray
|
Array of labelled regions. |
required |
spacing
|
float
|
Pixel to nm scaling. |
required |
Returns:
| Type | Description |
|---|---|
list[RegionProperties]
|
A list of |
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:
| Name | Type | Description | Default |
|---|---|---|---|
stacked_array
|
NDArray
|
Three-dimensional numpy array of image heights, each layer should be a copy of the original. |
required |
slices
|
int
|
Number of slices to mask. Determined directly from data if not provided (i.e. depth of three-dimensional array). |
None
|
layers
|
NDArray
|
Array of height thresholds for each slice. Determined directly from data if not provided. |
None
|
min_height
|
float64
|
Minimum height. Determined directly from data if not provided. |
None
|
max_height
|
float64
|
Maximum height. Determined directly from data if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
labelled_array
|
NDArray[int32]
|
A three-dimensional array with labelled regions. |
required |
properties
|
dict[int, Any]
|
The properties of labelled objects for each layer. |
required |
minimum_size
|
float
|
Minimum size below which labelled regions are removed. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
Masked array with labelled regions smaller than |
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:
| Name | Type | Description | Default |
|---|---|---|---|
labelled_array
|
NDArray[int32]
|
A three-dimensional array with labelled regions. |
required |
properties
|
dict[int, Any]
|
The properties of labelled objects for each layer. |
required |
minimum_size
|
float
|
Minimum size below which labelled regions are removed. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
Masked array with labelled regions smaller than |
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:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[int32]
|
Three-dimensional sliced and labelled array. |
required |
spacing
|
float
|
Pixel to nanometer scaling. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, Any]
|
Dictionary of |
Source code in src/afmslicer/slicer.py
segment(array, method='label', tidy_border=True, **kwargs)
¶
Segment an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray
|
Two-dimensional numpy array to segment. |
required |
method
|
str
|
Segmentation method, supports the |
'label'
|
tidy_border
|
bool
|
Whether to remove objects that straddle the border of the image. |
True
|
**kwargs
|
dict[str, Any]
|
Additional arguments to pass for segmentation. |
{}
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[bool]
|
Three-dimensional boolean array to be segmented. |
required |
method
|
str
|
Sgementation method to use. Currne options are |
'label'
|
tidy_border
|
bool
|
Whether to tidy the border. |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[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:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray
|
Three-dimensional numpy array. |
required |
Source code in src/afmslicer/slicer.py
slice_3d(array, scaling, binary=False)
¶
Convert a two-dimensional array of heights into a three-dimensional binary array.
Rather than taking a fixed number of slices as with slicer() we here use the observed range and the scaling,
which typically comes from the scan itself to determine the appropriate number of slices to take so that they are
correctly scaled to the same as the x/y axis of the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[float64]
|
A two-dimensional array of heights. |
required |
scaling
|
float
|
Pixel to nanometre scaling. |
required |
binary
|
bool
|
Whether to create a boolean array. If |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[int8, float64]
|
A three-dimensional array scaled by |
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:
| Name | Type | Description | Default |
|---|---|---|---|
heights
|
NDArray[float64]
|
Two-dimensional numpy array of heights. |
required |
slices
|
int
|
Number of slices to make. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Expanded numpy array with the original two-dimensional array copied |
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]]])