create_masked_array#

brainglobe_atlasapi.atlas_generation.volume_utils.create_masked_array(volume, label, greater_than=False)[source]#

Create a binary masked array from a volumetric dataset.

Given a 2D or 3D NumPy array and a label value (or list of labels), this function generates a binary array. The output array will have values of 1 where the volume matches the label (or is contained within the label list) and 0 otherwise. If greater_than is True, all voxels with values strictly greater than label will be set to 1.

Parameters:
  • volume (np.ndarray) – The input 2D or 3D NumPy array.

  • label (int, float, or list of int) – The value(s) to match in the volume. If greater_than is True, this should be a single numerical value.

  • greater_than (bool, optional) – If True, all voxels with values strictly greater than label will be set to 1. If False, voxels equal to label (or in the list of `label`s) will be set to 1. By default, False.

Returns:

A binary NumPy array with the same shape as volume, where matching (or greater than) voxels are 1 and others are 0.

Return type:

np.ndarray

Raises:

ValueError – If volume is not a NumPy array.