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}"

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source