Smoothing or registering
These examples show how to smooth data or register data in small memory bites using read loop. Commands are "jip smooth.com input 1.5" (1.5 mm smoothing kernel) and "jip register.com input" to read file "input.nii" and to output files "input-smooth.nii" or "input-reg.nii"
usage: jip smooth.com input 1.5 usage: jip register.com input
read-loop $1.nii read align-subject1.com
smooth-3d $2 read-loop $1.nii data
write $1-smooth.nii register data
end-loop write $1-reg.nii data
bye end-loop
bye
Averaging in 4 dimensions
4-D averaging can be useful for fMRI in cases where the response form is not known (e.g., a drug stimulus). When there are x*y*z*t voxels and n subjects, memory requirements can blow up. This shows how to create a subject-averaged time series by averaging small bites from each file.
usage: "jip average.com" to average 3 subjects with 550 time points each.
Note that subject data should be normalized 1st ("normalize" command) if the data are raw MRI signal levels, as opposed to a physiological quantity like fCBV or relaxation rate.
average.com and subjects.com
read subjects.com 0-99 read subject1.nii>$1 s1
read subjects.com 100-199 read subject2.nii>$1 s2
read subjects.com 200-299 read subject3.nii>$1 s3
read subjects.com 300-399 average-stacks av
read subject.com 400-n write average.bshort av
bye delete # clear memory
T2 or T2* maps
Creating maps of T2 or T2* is a simple procedure based upon fitting a series of data with different echo times. Assuming everything is maintained constant across acquisitions but the echo time, the MRI signal is S = S0 * exp(-TE*R2), where R2 = 1/T2 or 1/T2*. This can be linearized as y = mx + b, where y = ln(S), b = ln(S0), x = TE, and m = -R2. You can create a map like this:
read file1.nii TE5
read file2.nii TE10
read file3.nii TE15
read file4.nii TE20
read file5.nii TE25
smooth-3d 0.5 # optional step to decrease noise
write te-series.nii # it's always a good idea to view the TE series
set map-array 5 10 15 20 25 # ms
map-t2 map TE5 TE10 TE15 TE20 TE25 # map contains 3 volumes: R2, T2, and S0
multiply-constant 1000 map>0 # convert R2 to 1/sec
read brain.ovl # if working with aligned data, use an overlay ...
magnitude-window # ... to kill noise outside the brain (optional)
write map.bfloat map # outputs 3 maps (R2,T2,S0). Use .bfloat or .nii
write r2.bfloat map>0 # You can separate maps into different files.
bye
Creating your own template
Cross-subject registration based upon a template is a common function during analysis.
Let's suppose you have a template volume and you want to maintain the field of view for use with wire frames (which can generate overlays), but you want to change the resolution and perhaps the number of slices. This can be done by "jip make-template.com", which calls "resolution-250x250x1000.com". The file "make-template.com" is:
read template-rare.nii rare
read resolution-250x250x1000.com
register
write my-template.nii
bye
... and the file "resolution-250x250x1000.com" looks something like this:
# It is necessary to set the resolution and matrix size.
# If not set explictly, the origin and direction will be inherited.
# Matrix size: resolution * matrix should be conserved in each dimension.
# The original matrix is 64 x 50 x 42 with resolution 0.25 x 0.25 x 0.5
shift-pixels 0 0 -2 # This command keeps track of the origin!
clip-z-to 36 # now the z extent is 18 mm, not 21 mm
set registration-resolution 0.25 0.25 1
set registration-matrix 64 50 18