Parallel math#
These are methods for High-Performance Computing (HPC) operations for voxel by voxel image manipulation. They leverage both CPU and GPU parallelization techniques to perform a wide range of mathematical operations such as element-wise arithmetic and logical operations.
- VoxelImage.math(value, op, *, mask=None, segmentation=None, phases=None, region=None)[source]#
Parallel CPU GPU
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# opOperation
’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
phaseswill 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 inphaseswill 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.
- VoxelImage.combine(image, op, *, mask=None, segmentation=None, phases=None, region=None)[source]#
Parallel CPU GPU
Combine another voxel image by element-wise math operations.
This method applies math operations for each voxel in the images. Optional parameters allow for selective setting based on mask, segmentation, and phases.
- Parameters:
image (VoxelImage) –
The voxel image to be used in the operation. Must have shape, voxel origin, voxel length and voxel unit equal to the ones in the original array.
Note
There is no internal check for the correct data type of
a. Ensure that theaprovided is compatible with the image data type.op (str) –
The operation to be performed. Let \(voxel1\) represent each voxel in the original image and \(voxel2\) represent each voxel in
image. Valid values foropare:Operations# opOperation
’copy’
\(voxel1 = voxel2\)
’add’
\(voxel1 = voxel1 + voxel2\)
’subtract’
\(voxel1 = voxel1 - voxel2\)
’multiply’
\(voxel1 = voxel1 voxel2\)
’divide’
\(voxel1 = voxel1 / voxel2\)
’logical and’
\(voxel1 = voxel1 \land voxel2\)
’logical or’
\(voxel1 = voxel1 \lor voxel2\)
’logical xor’
\(voxel1 = voxel1 \oplus voxel2\) (exclusive OR)
’min’
\(voxel1 = \min(voxel1, voxel2)\)
’max’
\(voxel1 = \max(voxel1, voxel2)\)
’average’
\(voxel1 = (voxel1 + voxel2)/2\)
’absolute difference’
\(voxel1 = |voxel1 - voxel2|\)
mask (VoxelImage, optional) – Boolean voxel image. If provided, the operation will ignore masked voxels (i.e., where mask is True).
segmentation (VoxelImage, optional) – Unsigned integer voxel image. If provided, only voxels where the segmentation phase is in
phaseswill 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 inphaseswill 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.