fmri_processing_spm12r.Rmd
spm12r
functionsRequires MATLAB (installs SPM to R library)
spm12_slice_timing
- slices are not taken instantaneouslyspm12_realign
- people movespm12_coregister
- structural imaging is higher resolutionspm12_segment
- where’s the gray matter?spm12_normalize
- brains look better in MNIspm12_smooth
- turn that noise downWe will use the subject 113 from the Kirby21 data set to illustrate some basic operations of functional magnetic resonance imaging (fMRI). We will load in the T1 anatomical image and the fMRI from the respective packages.
library(kirby21.t1)
library(kirby21.fmri)
install_dir = tempdir()
outdir = tempfile()
dir.create(outdir)
stopifnot(download_fmri_data(outdir = outdir))
## cloning into '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d508b60169/kirby21.fmri'...
## Receiving objects: 1% (1/98), 8 kb
## Receiving objects: 11% (11/98), 8 kb
## Receiving objects: 21% (21/98), 8 kb
## Receiving objects: 31% (31/98), 8 kb
## Receiving objects: 41% (41/98), 41504 kb
## Receiving objects: 51% (50/98), 177339 kb
## Receiving objects: 61% (60/98), 267438 kb
## Receiving objects: 71% (70/98), 267438 kb
## Receiving objects: 81% (80/98), 267438 kb
## Receiving objects: 91% (90/98), 267438 kb
## Receiving objects: 100% (98/98), 267438 kb, done.
stopifnot(download_t1_data(outdir = outdir))
## cloning into '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d50651698f6/kirby21.t1'...
## Receiving objects: 1% (2/163), 12 kb
## Receiving objects: 11% (18/163), 12 kb
## Receiving objects: 21% (35/163), 12 kb
## Receiving objects: 31% (51/163), 15553 kb
## Receiving objects: 41% (67/163), 46558 kb
## Receiving objects: 51% (84/163), 46558 kb
## Receiving objects: 61% (100/163), 46558 kb
## Receiving objects: 71% (116/163), 46558 kb
## Receiving objects: 81% (133/163), 46558 kb
## Receiving objects: 91% (149/163), 46718 kb
## Receiving objects: 100% (163/163), 46774 kb, done.
functional = get_fmri_filenames(ids = 113, visit = 1, outdir = outdir)
anatomical = get_t1_filenames(ids = 113, visit = 1, outdir = outdir)
files = c(anatomical = anatomical,
functional = functional)
files
## anatomical
## "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d505645ecaf/visit_1/113/113-01-T1.nii.gz"
## functional
## "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d505645ecaf/visit_1/113/113-01-fMRI.nii.gz"
We know the repetition time (TR) is 2 seconds for this data. It may be encoded in the NIfTI file itself or come from a parameter file from the scanner. We will drop the first 20 seconds to allow for signal stabilization.
library(neurobase)
## Loading required package: oro.nifti
## oro.nifti 0.11.0
tr = 2 # seconds
DROP = 10 # 20 seconds for stabilization
fmri = readnii(files["functional"])
times = (DROP + 1):ntim(fmri)
run_fmri = copyNIfTIHeader(fmri, fmri[,,,times], drop = TRUE)
Now run_fmri
contains a nifti
object with the first 10 volumes dropped. We will pass this into the subsequent functions.
As SPM requires MATLAB and calls all the functions through the matlabr
package, we will have checks in this vignette/workflow that the user has MATLAB. The have_matlab()
function returns a logical that is TRUE
when matlabr
can find MATLAB to run the subsequent commands.
library(matlabr)
have_matlab()
## [1] TRUE
If this is not TRUE
, almost none of the functionality below will run because it would simply result in errors.
We will show how to do spatial realignment, slice-timing correction, spatial normalization to the MNI template (2 different ways), and spatial smoothing. Overall, there are many different ways to order these operations, with different options, so this represents just one way to organize a preprocessing pipeline.
Realignment is referring to in this case as within-subject registration of the 4D fMRI data.
library(spm12r)
####################################
# Realignment
####################################
realign_batch = build_spm12_realign(
filename = run_fmri,
register_to = "mean",
reslice = "mean"
)
## # Getting Number of Time Points
## # Reslice is mean
## [1] "spm" "script" "outfiles" "rp" "mean" "mat"
## [1] "spm.spatial.realign.estwrite.data"
## [2] "spm.spatial.realign.estwrite.eoptions.quality"
## [3] "spm.spatial.realign.estwrite.eoptions.sep"
## [4] "spm.spatial.realign.estwrite.eoptions.fwhm"
## [5] "spm.spatial.realign.estwrite.eoptions.rtm"
## [6] "spm.spatial.realign.estwrite.eoptions.interp"
## [7] "spm.spatial.realign.estwrite.eoptions.wrap"
## [8] "spm.spatial.realign.estwrite.eoptions.weight"
## [9] "spm.spatial.realign.estwrite.roptions.which"
## [10] "spm.spatial.realign.estwrite.roptions.interp"
## [11] "spm.spatial.realign.estwrite.roptions.wrap"
## [12] "spm.spatial.realign.estwrite.roptions.mask"
## [13] "spm.spatial.realign.estwrite.roptions.prefix"
if (have_matlab()) {
realigned = spm12_realign(
filename = run_fmri,
register_to = "mean",
reslice = "mean",
clean = FALSE,
install_dir = install_dir
)
print(names(realigned))
}
## cloning into '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12'...
## Receiving objects: 1% (68/6722), 23 kb
## Receiving objects: 11% (740/6722), 2971 kb
## Receiving objects: 21% (1412/6722), 3322 kb
## Receiving objects: 31% (2084/6722), 9475 kb
## Receiving objects: 41% (2757/6722), 10993 kb
## Receiving objects: 51% (3429/6722), 31451 kb
## Receiving objects: 61% (4101/6722), 36485 kb
## Receiving objects: 71% (4773/6722), 46985 kb
## Receiving objects: 81% (5445/6722), 70575 kb
## Receiving objects: 91% (6118/6722), 99263 kb
## Receiving objects: 100% (6722/6722), 131273 kb, done.
## # Getting Number of Time Points
##
## # Reslice is mean
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d50207b2a45.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d5014043617.m
## Command run is:
## matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d50207b2a45.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## [1] "spm" "script" "outfiles" "rp" "mean" "mat" "result"
Overall the spm12_realign
does the realignment. There is some discussion of performing realignment before slice-timing correction because estimation of motion parameters may be skewed after slice-timing correction. We see that the output realigned
has the output 4D fMRI data (outfiles
), the realignment parameters (rp
), voxel-wise mean after realignment (mean
), and the matrix of transformations for the 4D series (mat
).
Here we can read in the rp
file to show the estimated parameters. These can be used as regressors in motion correction for further analyses.
####################################
# Read in Motion data
####################################
if (have_matlab()) {
rpfile = realigned[['rp']]
rp = read.table(file = rpfile, header = FALSE)
colnames(rp) = c("x", "y", "z",
"roll", "pitch", "yaw")
rp = as.matrix(rp)
print(head(rp))
print(dim(rp))
}
## x y z roll pitch
## [1,] 0.00000000 0.000000000 -4.410886e-16 -5.015443e-37 1.253861e-37
## [2,] -0.03250006 0.022276041 6.105989e-02 -3.616417e-04 -1.389442e-04
## [3,] 0.02884634 -0.005311455 5.649025e-02 -3.774759e-04 -1.798493e-04
## [4,] 0.02379671 -0.056644719 2.574345e-02 5.180747e-05 -1.756995e-04
## [5,] 0.04293237 -0.056942376 2.414558e-02 -2.210120e-05 -8.367122e-05
## [6,] 0.02858868 -0.038461745 8.289177e-02 -2.785027e-04 -3.532936e-04
## yaw
## [1,] 6.288666e-74
## [2,] -2.732142e-04
## [3,] 1.048090e-04
## [4,] -6.489734e-06
## [5,] 2.291027e-04
## [6,] -8.279382e-06
## [1] 200 6
A slice-timing correction does interpolation since each slice was not actually taken at the same time point, but a shifted time point over the course of an entire TR. The correction requires you to input the reference slice (in this case the median, ref_slice
), the repetition time (tr
), time between the first and the last slice within one scan (ta
), and the order the slices were acquired. In our case, it was done in an ascending, contiguous order, so we created the slice order as such. If you used descending or interleaved acquisition, then this must be changed accordingly.
####################################
# Slice Timing Correction
####################################
nslices = oro.nifti::nsli(run_fmri)
slice_order = 1:nslices
ref_slice = slice_order[median(seq(nslices))]
ta = tr - tr/nslices
n_time_points = ntim(run_fmri)
# using run_fmri because if you do not have
# matlab, then realigned not available
st_batch = build_spm12_slice_timing(
filename = run_fmri,
time_points = seq(n_time_points),
nslices = nslices,
tr = tr,
ref_slice = ref_slice,
prefix = "a")
print(names(st_batch))
## [1] "spm" "script" "orig_filename"
## [4] "base_name" "temporary_directory" "outfile"
## [1] "spm.temporal.st.scans" "spm.temporal.st.nslices"
## [3] "spm.temporal.st.tr" "spm.temporal.st.ta"
## [5] "spm.temporal.st.so" "spm.temporal.st.refslice"
## [7] "spm.temporal.st.prefix"
if (have_matlab()) {
st_results = spm12_slice_timing(
filename = realigned[['outfiles']],
time_points = seq(n_time_points),
nslices = nslices,
tr = tr,
slice_order = slice_order,
ta = ta,
ref_slice = ref_slice,
prefix = "a",
clean = FALSE,
retimg = FALSE,
install_dir = install_dir
)
aimg = st_results$outfile
print(aimg)
mean_img = realigned[["mean"]]
mean_nifti = readnii(mean_img)
}
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d508e3146.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d5022763cbf.m
## Command run is:
## matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d508e3146.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/afile9d507844648c.nii"
We see the output aimg
has the filename of the slice-timing corrected 4D image. We also read in the mean image into a nifti
object (mean_nifti
).
if (!have_matlab()) {
run_fmri = filename_check(run_fmri)
}
For the subsequent image normalization steps, SPM assumes the data is aligned along the anterior commissure (AC) posterior commissure (PC) line (AC-PC). The acpc_reorient
function (based on nii_setOrigin
from Dr. Chris Rorden) will do this. The syntax is that the first file (mean_img
) is used to estimate the line/plane and the subsequent files are reoriented using this estimation (aimg
). These are changes to the header of the image and the image with the new header is written to the same file as the input file.
if (have_matlab()) {
acpc_reorient(
infiles = c(mean_img, aimg),
modality = "T1",
install_dir = install_dir
)
}
##
## #Reorientation /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/meanfile9d507844648c.nii
## Script created: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d507b183d54.m
## Command run is:
## matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d507b183d54.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/meanfile9d507844648c.nii
## "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/meanfile9d507844648c.nii"
## /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/afile9d507844648c.nii
## "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/afile9d507844648c.nii"
Here, we will spatially normalize the fMRI to the MNI template using spm12_normalize
. Here we specify a standard bounding box for a 2mm MNI template. We are taking the mean image and directly registering it to the MNI template (T1-weighted), and applying that transform to the other.files
, in this case the mean image and the 4D fMRI image.
if (have_matlab()) {
bbox = matrix(
c(-90, -126, -72,
90, 90, 108),
nrow = 2, byrow = TRUE)
print(bbox)
direct_norm = spm12_normalize(
filename = mean_img,
other.files = c(mean_img, aimg),
bounding_box = bbox,
clean = FALSE,
install_dir = install_dir
)
print(names(direct_norm))
dnorm_files = direct_norm$outfiles
dnorm_mean_img = readnii(dnorm_files[1])
}
## [,1] [,2] [,3]
## [1,] -90 -126 -72
## [2,] 90 90 108
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Normalize_Estimate_and_Write_job.m
## Command run is:
## matlab -nodesktop -nosplash -singleCompThread -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## [1] "spm" "script" "outfiles" "result"
We see the output direct_norm
is a list with the output files (outfiles
). The order of these files is the same as the order of those put in. In this case, the first file of outfiles
is the normalized mean image and second is the normalized 4D image. Here we read in the spatially normalized mean image to compare to the template later.
Indirect normalization refers to spatially normalizing the co-registered anatomical T1-weighted image to the MNI template. This transformation is applied to the mean image and 4D fMRI image. This is also referred to as Unified Segmentation.
Here we will perform the registration of the T1-weighted anatomical image into the space of the mean fMRI image after realignment. This is referred to as “co-registration” as it is within-subject registration, but across modalities (where we referred to within-subject, within-modality as realignment).
Here, we also reorient the anatomical image the AC-PC line. We then perform the coregistration using spm12_coregister
, where the fixed image is the mean image and the moving image is the anatomical.
if (have_matlab()) {
anatomical = files["anatomical"]
anat_img = checknii(anatomical)
print(anat_img)
acpc_reorient(
infiles = anat_img,
modality = "T1",
install_dir = install_dir
)
coreg = spm12_coregister(
fixed = mean_img,
moving = anat_img,
prefix = "r",
install_dir = install_dir
)
coreg_anat = coreg$outfile
coreg_img = readnii(coreg_anat)
double_ortho(coreg_img, mean_nifti)
}
## [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/113-01-T1.nii"
## attr(,"nbrOfBytes")
## [1] 44564832
##
## #Reorientation /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpEBqTe9/113-01-T1.nii
## Script created: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d507ee6d210.m
## Command run is:
## matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d507ee6d210.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## Checking Filenames
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d50301e067a.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d506cf49fa8.m
## Command run is:
## matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/file9d50301e067a.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
## Warning in datatyper(nim, warn = warn): Need to change bitpix and datatype to
## FLOAT64 due to NAs
We see the anatomical image has been transformed and resliced into the mean fMRI image space (and thus has the resolution of that image).
Here we perform the segmentation of the co-registered anatomical image from above. This will segment the image into 6 different regions, where the regions are gray matter, white matter, cerebrospinal fluid (CSF), bone, soft tissue, and the background. You should inspect these visually before using them to ensure quality and no reordering due to artifacts.
if (have_matlab()) {
seg_res = spm12_segment(
filename = coreg_anat,
set_origin = FALSE,
retimg = FALSE,
clean = FALSE,
install_dir = install_dir
)
print(names(seg_res))
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Segment_job.m
## Command run is:
## matlab -nodesktop -nosplash -singleCompThread -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## [1] "spm" "script" "result"
## [4] "outfiles" "outmat" "deformation"
## [7] "inverse_deformation"
In order to segment the image, SPM spatially normalizes the image to the MNI template, however. This transformation will be the one we use to transform the fMRI data to MNI space. We see in seg_reg
a deformation
file, which is the transformation. We also see the output segmentation files of the probability of each class, in native space. We only tend to care about the first 3 categories.
If you would like to convert these class probabilities to a “hard” segmentation, you must read the data in and use spm_probs_to_seg
for that. In spm_probs_to_seg
, each voxel is assigned the class with the maximum probability, with options on how to choose ties (first is default). We can then remove the labels for bone, soft tissue, and background (> 3
).
alpha = function(col, alpha = 1) {
cols = t(col2rgb(col, alpha = FALSE)/255)
rgb(cols, alpha = alpha)
}
if (have_matlab()) {
seg_files = check_nifti(seg_res$outfiles)
hard_seg = spm_probs_to_seg(seg_files)
hard_seg[ hard_seg > 3] = 0
ortho2(coreg_img, hard_seg,
col.y = alpha(c("red", "green", "blue"), 0.5))
}
Now that we have estimated the transformation from the T1 image, we can take that deformation and apply it to the fMRI data using spm12_normalize_write
. Again, we are registering to the MNI template and will use a standard bounding box. We pass the anatomical, mean fMRI, and 4D fMRI data in to be transformed.
bbox = matrix(
c(-90, -126, -72,
90, 90, 108),
nrow = 2, byrow = TRUE)
if (have_matlab()) {
norm = spm12_normalize_write(
deformation = seg_res$deformation,
other.files = c(coreg_anat, mean_img, aimg),
bounding_box = bbox,
retimg = FALSE,
install_dir = install_dir
)
print(names(norm))
norm_data = norm$outfiles
names(norm_data) = c("anat", "mean", "fmri")
norm_mean_img = readnii(norm_data["mean"])
norm_anat_img = readnii(norm_data["anat"])
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Normalize_Write_job.m
## Command run is:
## matlab -nodesktop -nosplash -singleCompThread -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
## [1] "spm" "script" "deformation" "other_fnames" "outfiles"
## [6] "result"
## Warning in datatyper(nim, warn = warn): Need to change bitpix and datatype to
## FLOAT64 due to NAs
Now we have the indirect spatially normalized data in MNI template space
Here we will use the MNI 152 template to view results (the one we registered to). We create some crude masks to see how the overall brain overlaps with the template to make some comparisons.
if (have_matlab()) {
template_path = file.path(spm_dir(),
"canonical", "avg152T1.nii")
template = readnii(template_path)
dnorm_mask = dnorm_mean_img > quantile(
dnorm_mean_img[dnorm_mean_img > 0],
probs = 0.6)
norm_mask = norm_mean_img > quantile(
norm_mean_img[norm_mean_img > 0],
probs = 0.6)
double_ortho(template, norm_anat_img)
double_ortho(template, norm_mean_img)
double_ortho(norm_mean_img, norm_anat_img)
ortho2(template, norm_mask, col.y = alpha("red", 0.5))
double_ortho(template, dnorm_mean_img)
ortho2(template, dnorm_mask, col.y = alpha("red", 0.5))
double_ortho(norm_mean_img, dnorm_mean_img)
}
Here we will perform spatial smoothing of the 4D fMRI data in template space. We can set the full-width half max (FWHM) for the Gaussian smoother. The relationship between the FWHM and the Gaussian standard deviation is:
\[ FWHM = \sigma \sqrt{8 \log(2)} \] where \(\log\)` is the natural log.
if (have_matlab()) {
smoothed = spm12_smooth(
filename = norm_data["fmri"],
fwhm = 8,
prefix = "s",
retimg = FALSE,
install_dir = install_dir
)
smoothed_data = smoothed$outfiles
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Smooth_job.m
## Command run is:
## matlab -nodesktop -nosplash -singleCompThread -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
In many applications, this is the data you will use for post-processing and analysis. Motion correction has usually been applied above, but some motion correct this data as well.
if (have_matlab()) {
smoothed_mean = spm12_smooth(
filename = norm_data["mean"],
prefix = "s",
retimg = FALSE,
install_dir = install_dir
)
smoothed_mean_data = smoothed_mean$outfiles
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Smooth_job.m
## Command run is:
## matlab -nodesktop -nosplash -singleCompThread -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpEBqTe9/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
Here we can smooth the mean image in MNI space. We could have also calculated a new mean image and smoothed that. Or we could have calculated a mean of the smoothed 4D data. They all may be slightly different.
if (have_matlab()) {
smooth_mean_img = readnii(smoothed_mean_data)
ortho2(smooth_mean_img)
}