Slicer
Module for slicing two-dimensional arrays to three-dimensional arrays of stacked masks.
Functions:
| Name | Description |
|---|---|
calculate_region_properties |
Calculate the region properties on a segmented array. |
mask_slices |
Convert a three-dimensional sliced array into masks based. |
mask_small_artefacts |
Mask labelled features that are less than a specified size from two-dimensional array. |
mask_small_artefacts_all_layers |
Mask labelled features that are less than a specified size from three-dimensional array. |
region_properties_by_slices |
Calculate region properties for each layer in a three-dimensinoal sliced array. |
segment |
Segment an array. |
segment_slices |
Segment individual layers of a three-dimensional numpy array. |
show_layers |
Helper function for debugging which shows individual layers of a three-dimensional numpy array. |
slice_3d |
Convert a two-dimensional array of heights into a three-dimensional binary array. |
slicer |
Convert a two-dimensional array to a three-dimensional stacked array with copies of the original in each layer. |
calculate_region_properties
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 |
|---|---|---|---|
|
NDArray
|
Array of labelled regions. |
required |
|
float
|
Pixel to nm scaling. |
required |
Returns:
| Type | Description |
|---|---|
list[RegionProperties]
|
A list of |
mask_slices
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 |
|---|---|---|---|
|
NDArray
|
Three-dimensional numpy array of image heights, each layer should be a copy of the original. |
required |
|
int
|
Number of slices to mask. Determined directly from data if not provided (i.e. depth of three-dimensional array). |
None
|
|
NDArray
|
Array of height thresholds for each slice. Determined directly from data if not provided. |
None
|
|
float64
|
Minimum height. Determined directly from data if not provided. |
None
|
|
float64
|
Maximum height. Determined directly from data if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[bool]
|
Three-dimensional array of masks. |
mask_small_artefacts
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 |
|---|---|---|---|
|
NDArray[int32]
|
A three-dimensional array with labelled regions. |
required |
|
dict[int, Any]
|
The properties of labelled objects for each layer. |
required |
|
float
|
Minimum size below which labelled regions are removed. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
Masked array with labelled regions smaller than |
mask_small_artefacts_all_layers
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 |
|---|---|---|---|
|
NDArray[int32]
|
A three-dimensional array with labelled regions. |
required |
|
dict[int, Any]
|
The properties of labelled objects for each layer. |
required |
|
float
|
Minimum size below which labelled regions are removed. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
Masked array with labelled regions smaller than |
region_properties_by_slices
Calculate region properties for each layer in a three-dimensinoal sliced array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray[int32]
|
Three-dimensional sliced and labelled array. |
required |
|
float
|
Pixel to nanometer scaling. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, Any]
|
Dictionary of |
segment
segment(array, method='label', tidy_border=True, **kwargs)
Segment an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray
|
Two-dimensional numpy array to segment. |
required |
|
str
|
Segmentation method, supports the |
'label'
|
|
bool
|
Whether to remove objects that straddle the border of the image. |
True
|
|
dict[str, Any]
|
Additional arguments to pass for segmentation. |
{}
|
Returns:
| Type | Description |
|---|---|
NDArray
|
Labelled array of objects. |
segment_slices
segment_slices(array, method='label', tidy_border=False)
Segment individual layers of a three-dimensional numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray[bool]
|
Three-dimensional boolean array to be segmented. |
required |
|
str
|
Sgementation method to use. Currne options are |
'label'
|
|
bool
|
Whether to tidy the border. |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[bool]
|
Three-dimensional array of labelled layers. |
show_layers
show_layers(array)
Helper function for debugging which shows individual layers of a three-dimensional numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray
|
Three-dimensional numpy array. |
required |
slice_3d
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 |
|---|---|---|---|
|
NDArray[float64]
|
A two-dimensional array of heights. |
required |
|
float
|
Pixel to nanometre scaling. |
required |
|
bool
|
Whether to create a boolean array. If |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[int8, float64]
|
A three-dimensional array scaled by |
slicer
Convert a two-dimensional array to a three-dimensional stacked array with copies of the original in each layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray[float64]
|
Two-dimensional numpy array of heights. |
required |
|
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]]])