Home

Awesome

About

Neuroimaging data is ofter blurred with a Gaussian smoothing kernel. This step can remove noise spikes, improve signal-to-noise, reduce effective number of statistical comparisons and helps ensure data roughly matches the assumptions of the general linear model statistics. While niave implementations of the Gaussian blur are slow, it is a separable filter, so we can process each dimension sequentially. Within each dimension, we can process all the lines in parallel. This simple project provides a high performance implementation and compares favorably to other tools.

This tool use the CPU, and therefore does not require a graphics card that supports GLSL or CUDA. It should be noted that graphics cards have a huge number of cores and hardware-based sampling that can aid Gaussian blurs. On the other hand, graphics cards have slow memory latency, these operations are probably memory bound for typical neuroimaging datasets.

This software can read any of the medical formats supported by i2nii, but it only writes NIfTI format images.

Installation

You can get Depth3D using two methods:

Usage

Chris Rorden's niiSmooth v1.0.20191206
usage: niiSmooth [options] <in_file(s)>
Reads volume and computes distance fields
OPTIONS
 -3 : save 4D data as 3D files (y/n, default n)
 -f : full-width half maximum in mm (default 8)
 -d : output datatype (in/u8/u16/f32 default in)
 -h : show help
 -m : mask name (optional, only weight voxels in mask)
 -o : output name (omit to save as input name with "depth_" prefix)
 -p : parallel threads (0=optimal, 1=one, 5=five, default 0)
 -z : gz compress images (y/n, default n)
 Examples :
  niiSmooth -f 8 fmri.nii
  niiSmooth -f 4 -m T1mask.nii T1.nii

Performance

Here is the time to convert a 345mb resting state dataset (90x90x50x427 16-bit) with a 6mm FWHM on a 12-core (24-thread) Ryzen 3900X computer.

ToolTime (.nii)Time (.nii.gz)
AFNI<sup>1</sup>1.524.3
niiSmooth<sup>2</sup>2.33.6<sup>3</sup>
c4d16.740.0
FSL20.044.3
SPM1222.2-
  1. By default, AFNI uses a smaller, faster, and less precise kernel width (AFNI_BLUR_FIRFAC) than other methods. AFNI uses parallel pigz for compressing for BRIK.GZ (3.1s) but not .nii.gz (24.3s).
  2. niiSmooth requires 7.3s to create uncompressed .nii in single-threaded mode
  3. niiSmooth (and AFNI when creating BRIK.GZ) can use pigz to accelerate compression. These times are with the default version of pigz, and compression will be accelerated a futuer 40% if the user installs an optimized version of pigz.
//High performance smoothing
//Note some tools use FWHM others use Sigma, 6mm FWHM = 2.548mm Sigma 
//Set ~/.afnirc for AFNI_COMPRESSOR = pigz
niiSmooth -f 6 -d f32 ~/Neuro/rest.nii
time niiSmooth -f 6 -d f32 -z y ~/Neuro/rest.nii
time niiSmooth -f 6 -d f32  -p 1 ~/Neuro/rest.nii
time fslmaths rest.nii -s 2.548 fsl 
FSLOUTPUTTYPE=NIFTI; time fslmaths rest.nii -s 2.5480 fsl
time c4d ~/Neuro/rest.nii -smooth 2.548mm -o c3d.nii
time c4d ~/Neuro/rest.nii -smooth 2.548mm -o c3d.niigz
time 3dmerge -1blur_fwhm 6.0 -doall -prefix afni.nii rest.nii
time 3dmerge -1blur_fwhm 6.0 -doall -prefix afni.nii.gz rest.nii
time 3dmerge -1blur_fwhm 6.0 -doall -prefix afni.brik.gz rest.nii
//next command from Matlab
tic; spm_smooth('rest.nii','spm.nii',6); toc

Compiling

Most people will want to download a pre-compiled executable. However, it is easy to compile.

 fpc -CX -Xs -XX -O3 niiSmooth