fslinfo code example

Example: fslinfo

#!/bin/sh

# Use fslinfo to extract image dimensions.  See fslhd for extraction of more info.

# find only the first matching line (-m 1) , print arg2: 
# this will get the # of voxels in dimension 1 (usually x).
dim1=$(fslinfo img | grep -m 1 dim1 | awk '{print $2}')

# find only the first matching line, print arg2: 
# this will get image dim this will get the voxel size in dimension 1 (usually x).
pixdim1=$(fslinfo img | grep -m 1 pixdim1 | awk '{print $2}')

# find only the first matching line (-m 1) , print arg2: 
# this will get this will get the # of voxels in dimension 2 (usually y).
dim2=$(fslinfo img | grep -m 1 dim2 | awk '{print $2}')

# find only the first matching line, print arg2: 
# this will get this will get the voxel size in dimension 2 (usually y).
pixdim2=$(fslinfo img | grep -m 1 pixdim2 | awk '{print $2}')

# find only the first matching line (-m 1) , print arg2:
# this will get the # of voxels in dimension 3 (usually z)
dim3=$(fslinfo img | grep -m 1 dim3 | awk '{print $2}')

# find only the first matching line, print arg2: 
# this will get the voxel size in dimension 3 (usually z).
pixdim3=$(fslinfo img | grep -m 1 pixdim3 | awk '{print $2}')

# find only the first matching line (-m 1) , print arg2: 
# this will get image dim
dim4=$(fslinfo img | grep -m 1 dim4 | awk '{print $2}')

# find only the first matching line, print arg2: 
# this will get the # of voxels in dimension 4 (usually time, hence, the # of timepoints).
pixdim4=$(fslinfo img | grep -m 1 pixdim4 | awk '{print $2}')

echo "voxel dims: ${pixdim1} x ${pixdim2} x ${pixdim3} x ${pixdim4} "
echo "image dims:  ${dim1} x ${dim2} x ${dim3} x ${dim4}"