fsl NAN code example

Example 1: fslmaths

#!/bin/sh

# Any image containing NANs may not be read correctly 
# by fslmaths or fslstats.
# -nan : replace NaNs (improper numbers) with 0

fslmaths img -nan img_no_nans

Example 2: fslstats

#!/bin/sh

# Get mean (-M) and standard deviation (-S) of a masked (-k) region 
# (e.g., a statistical image)

fslstats img_stats -k mask -M -S

# Test if an image is a binary mask:
# -M gets the mean of non-zero voxels.  
# -S gets the standard deviation of non-zero voxels.
# Beware of images containing NANs!
# The mean should be 1 
# The standard deviation should be 0 

fslstats img_mask -M -S