Skip to main content

convolve3d

Function convolve3d 

Source
pub fn convolve3d(
    volume: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>,
    kernel: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>,
    padding: Padding3D,
) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>, NdimageError>
Expand description

3D discrete convolution.

Convolves volume with kernel using the chosen padding strategy. The kernel is flipped (mirrored) along all three axes before sliding, which is the definition of mathematical convolution.

§Arguments

  • volume - Input 3D array.
  • kernel - Convolution kernel (any odd-or-even size is accepted).
  • padding - Border handling strategy.

§Returns

An Array3<f64> with the same shape as volume.

§Errors

Returns NdimageError::InvalidInput if the kernel has zero extent on any axis.

§Example

use scirs2_ndimage::convolution3d::{convolve3d, Padding3D};
use scirs2_core::ndarray::Array3;

let vol = Array3::<f64>::ones((8, 8, 8));
let kernel = Array3::<f64>::ones((3, 3, 3));
let out = convolve3d(&vol, &kernel, Padding3D::Zero).unwrap();
assert_eq!(out.shape(), [8, 8, 8]);