filters#

voxel.filters.gaussian_filter(volume, sigma, *components, space=None, truncate=2.0, stride=1, separable=True, padding_mode='replicate') → Volume#

Apply Gaussian smoothing to a volume.

Parameters:
  • sigma (float or Tensor) – Standard deviation(s) of size \((1,)\) or \((3,)\).

  • *components (float) – Additional components of sigma, allowing values to be passed as separate positional arguments, e.g. gaussian_filter(vol, 1, 1, 2, 'voxel').

  • space (Space) – The space of the sigma values, either ‘voxel’ or ‘world’. Can be provided as the last positional argument.

  • truncate (float, optional) – The number of standard deviations to extend the kernel before truncating.

  • stride (int or Tensor, optional) – Downsampling stride(s) in voxel units.

  • separable (bool, optional) – Whether to filter with three separable 1D kernels or a single dense 3D kernel. The results are equivalent.

  • padding_mode (str, optional) – Border padding mode, e.g. ‘replicate’ or ‘zeros’.

Returns:

Volume – Smoothed floating-point volume.

voxel.filters.box_filter(volume, size, *components, space=None, stride=1, separable=True, padding_mode='replicate') → Volume#

Apply mean filtering to a volume with a box kernel.

The box extent is rounded to the nearest odd number of voxels along each dimension.

Parameters:
  • size (float or Tensor) – Box extent(s) of size \((1,)\) or \((3,)\).

  • *components (float) – Additional components of size, allowing values to be passed as separate positional arguments, e.g. box_filter(vol, 3, 3, 1, 'voxel').

  • space (Space) – The space of the size values, either ‘voxel’ or ‘world’. Can be provided as the last positional argument.

  • stride (int or Tensor, optional) – Downsampling stride(s) in voxel units.

  • separable (bool, optional) – Whether to filter with three separable 1D kernels or a single dense 3D kernel. The results are equivalent.

  • padding_mode (str, optional) – Border padding mode, e.g. ‘replicate’ or ‘zeros’.

Returns:

Volume – Filtered floating-point volume.

voxel.filters.apply_filter(volume, kernel, stride=1, padding_mode='replicate') → Volume#

Apply a filter kernel to a volume with ‘same’-style output extents.

Channels are filtered independently. When strided, the grid is downsampled to a spatial size of \(ceil(baseshape / stride)\) and the volume geometry is updated to reflect the new voxel spacing.

Parameters:
  • kernel (Tensor or list) – A single dense 3D kernel of shape \((W, H, D)\) or a sequence of three 1D kernels applied separably per dimension.

  • stride (int or Tensor, optional) – Downsampling stride(s) in voxel units.

  • padding_mode (str, optional) – Border padding mode, e.g. ‘replicate’ or ‘zeros’.

Returns:

Volume – Filtered floating-point volume.

voxel.filters.gaussian_kernel_1d(sigma, truncate=2.0, device=None, dtype=None) → Tensor#

Generate a 1D Gaussian kernel with a specified standard deviation.

Parameters:
  • sigma (float) – Standard deviation in element (voxel) space.

  • truncate (float, optional) – The number of standard deviations to extend the kernel before truncating.

  • device (torch.device, optional) – The device on which to create the kernel.

  • dtype (torch.dtype, optional) – The kernel datatype.

Returns:

Tensor – A normalized kernel of length \(2 * int(truncate * sigma + 0.5) + 1\).