- Home
- Neuroconductor Tutorials
- Preprocess mri within
Processing Within-Visit MRI
John Muschelli
2017-12-20
All code for this document is located at here.
In this tutorial we will discuss within a visit registration (co-registration) of multi-sequence MRI images.
1 Data Packages
For this analysis, I will use one subject from the Kirby 21 data set. The kirby21.base
and kirby21.fmri
packages are necessary for this analysis and have the data we will be working on. You need devtools to install these. Please refer to installing devtools for additional instructions or troubleshooting.
packages = installed.packages()
packages = packages[, "Package"]
if (!"kirby21.base" %in% packages) {
source("https://neuroconductor.org/neurocLite.R")
neuroc_install("kirby21.base")
}
if (!"kirby21.smri" %in% packages) {
source("https://neuroconductor.org/neurocLite.R")
neuroc_install("kirby21.smri")
}
if (!"EveTemplate" %in% packages) {
source("https://neuroconductor.org/neurocLite.R")
neuroc_install("EveTemplate")
}
2 Loading Data
We will use the get_image_filenames_df
function to extract the filenames on our hard disk for the T1 image.
library(kirby21.smri)
library(kirby21.base)
run_mods = c("T1", "T2", "FLAIR")
fnames = get_image_filenames_list_by_visit(
ids = 113,
modalities = run_mods,
visits = c(1,2 ))
visit_1 = fnames$`1`$`113`
visit_2 = fnames$`2`$`113`
mods = visit_1 %>% nii.stub(bn = TRUE) %>%
strsplit("-") %>%
sapply(dplyr::last)
names(visit_1) = names(visit_2) = mods
visit_1 = visit_1[run_mods]
visit_2 = visit_2[run_mods]
3 Processing images within a visit
The function preprocess_mri_within
from extrantsr
wraps a series of steps. The function below will perform:
- N4 inhomogeneity (Tustison et al. 2010) correction to each image.
- Estimate the transformation to the first file (T1 image).
- Perform this transformation, registering the images, and interpolating the images using a Lanczos windowed sinc interpolator.
preprocess_mri_within
can also perform skull stripping using BET, but we have shown in the brain extraction tutorial that running BET without running neck removal.
library(extrantsr)
outfiles = nii.stub(visit_1, bn = TRUE)
proc_files = paste0(outfiles, "_proc.nii.gz")
names(proc_files) = names(outfiles)
if (!all(file.exists(proc_files))) {
extrantsr::preprocess_mri_within(
files = visit_1,
outfiles = proc_files,
correct = TRUE,
retimg = FALSE,
correction = "N4")
}
proc_imgs = lapply(proc_files, readnii)
lapply(proc_imgs, ortho2)