Skip to content

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.

slicer

Convert a two-dimensional array to a three-dimensional stacked array with copies of the original in each layer.

calculate_region_properties

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 RegionProperties.

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

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.

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

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 minimum_size masked.

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

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 minimum_size masked.

region_properties_by_slices

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 regionprops calculated using skimage.

segment

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 (default) and watershed methods implemented by Scikit Image.

'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.

segment_slices

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 (default) and watershed.

'label'

tidy_border

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

array

NDArray

Three-dimensional numpy array.

required

slicer

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 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]]])