unravel.image_tools.spatial_averaging module#

Use img_spatial_avg (spatial_avg) from UNRAVEL to load an image and apply 2D or 3D spatial averaging.

Inputs:
  • 3D image: .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr

Outputs:
  • Determined by the extension for .nii.gz and .zarr. Otherwise, saves as a .tif series.

Note

  • 3D averaging: Applies a 3x3x3 kernel to each voxel and its 26 neighbors.

  • 2D averaging: Applies a 3x3 kernel to each 2D slice independently.

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

  • Edges are zero-padded to preserve dimensions.

  • For .nii.gz output, you must specify both xy and z resolutions.

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]#