unravel.image_tools.spatial_averaging module#

Use img_spatial_avg from UNRAVEL to load an image and apply 3D spatial averaging.

Input image types:
  • .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr

Outputs:
  • .nii.gz, .tif series, or .zarr depending on the output path extension.

3D spatial averaging:
  • Apply a 3D spatial averaging filter to a 3D numpy array.

  • Default kernel size is 3x3x3, for the current voxel and its 26 neighbors.

  • The output array is the same size as the input array.

  • The edges of the output array are padded with zeros.

  • The output array is the same data type as the input array.

  • The input array must be 3D.

  • The xy and z resolutions are required for saving the output as .nii.gz.

  • The output is saved as .nii.gz, .tif series, or .zarr.

2D spatial averaging:
  • Apply a 2D spatial averaging filter to each slice of a 3D numpy array.

  • Default kernel size is 3x3, for the current pixel and its 8 neighbors.

  • The output array is the same size as the input array.

  • The edges of the output array are padded with zeros.

  • The output array is the same data type as the input array.

  • The input array must be 3D.

  • The xy and z resolutions are required for saving the output as .nii.gz.

  • The output is saved as .nii.gz, .tif series, or .zarr.

Usage:#

img_spatial_avg -i <tif_dir> -o spatial_avg.zarr -d 2 [-k 3] [-c 0] [-x 3.5232] [-z 6] [-dt uint16] [-r metadata_referenece.nii.gz] [-ao xyz] [-v]

unravel.image_tools.spatial_averaging.parse_args()[source]#
unravel.image_tools.spatial_averaging.spatial_average_3D(arr, kernel_size=3)[source]#

Apply a 3D spatial averaging filter to a 3D numpy array.

Parameters: - arr (np.ndarray): The input 3D array. - kernel_size (int): The size of the cubic kernel. Default is 3, for the current voxel and its 26 neighbors.

Returns: - np.ndarray: The array after applying the spatial averaging.

unravel.image_tools.spatial_averaging.apply_2D_mean_filter(slice, kernel_size=(3, 3))[source]#

Apply a 2D mean filter to a single slice.

unravel.image_tools.spatial_averaging.spatial_average_2D(volume, filter_func, kernel_size=(3, 3), threads=8)[source]#

Apply a specified 2D filter function to each slice of a 3D volume in parallel.

Parameters: - volume (np.ndarray): The input 3D array. - filter_func (callable): The filter function to apply to each slice. - kernel_size (tuple): The dimensions of the kernel to be used in the filter. - threads (int): The number of parallel threads to use.

Returns: - np.ndarray: The volume processed with the filter applied to each slice.

unravel.image_tools.spatial_averaging.main()[source]#