rockverse.voxel_image.VoxelImage.math#

VoxelImage.math(value, op, *, mask=None, segmentation=None, phases=None, region=None)[source]#

Element-wise math operations.

This method applies math operations for each voxel in the image. Optional parameters allow for selective setting based on mask, segmentation, and phases.

Parameters:
  • value (scalar) –

    The value to be used in the operation.

    Note

    There is no internal check for the correct data type of value. Ensure that the value provided is compatible with the image data type.

  • op (str) –

    The operation to be performed. Let \(voxel\) represent each voxel in the image. See table below:

    Operations#

    op

    Operation

    ’set’

    \(voxel = value\)

    ’add’

    \(voxel = voxel + value\)

    ’subtract’

    \(voxel = voxel - value\)

    ’multiply’

    \(voxel = voxel \times value\)

    ’divide’

    \(voxel = voxel / value\)

    ’logical and’

    \(voxel = voxel \land value\)

    ’logical or’

    \(voxel = voxel \lor value\)

    ’logical xor’

    \(voxel = voxel \oplus value\) (exclusive OR)

    ’min’

    \(voxel = \min(voxel, value)\)

    ’max’

    \(voxel = \max(voxel, value)\)

  • mask (voxel image, optional) – Boolean voxel image. If provided, the operation will ignore masked voxels (i.e., where mask is True).

  • segmentation (voxel image, optional) – Unsigned integer voxel image. If provided, only voxels where the segmentation phase is in phases will be set to the specified value.

  • phases (iterable of int, optional) – Any iterable with non negative integers representing the segmentation phases. Used together with segmentation. Segmentation phases not in phases will be ignored by the operation.

  • region (Region, optional) – A region specification. If provided, only voxels within the specified region will be set to the specified value.