Rxnat Paper Case Scenario

Rxnat Paper Case Scenario

Adi Gherman


All code for this document is located at here.

In this tutorial I will discuss performing tissue class segmentation using the FAST function from FSL and it’s wrapper function in fslr, fast_nobias (Muschelli et al. 2015).

Data Packages

To perform this analysis, I will select one subject from the IXI neuroimaging dataset hosted on https://nitrc.org/ (Kennedy et al. 2016). The Rxnat package is required to be installed in order to access the NITRC image repository as well as an account with NITRC: new account request

packages = installed.packages()
packages = packages[, "Package"]
if (!"Rxnat" %in% packages) {

Loading Data

Please visit the general Rxnat tutorial on how to setup the Rxnat environment variables. Next we’ll read and reorient the T1 image using the readrpi function from the fslr package.

nitrc <- xnat_connect("https://nitrc.org/ir", xnat_name="NITRC")
# Download the subject T1 weighted image
file_path <- nitrc$download_dir(
                experiment_ID = 'NITRC_IR_E10464',
                scan_type = "T1",
                extract = TRUE)
t1_fname <- file_path[1]
t1 <- readrpi(t1_fname)
ortho2(t1, add.orient = TRUE)
T1 Weighted Image

T1 Weighted Image

Remove neck and drop empty dimensions

The neck removal step is implemented using the remove_neck function from the extrantsr package. The empty image dimensions (including the neck slices) can be dropped by using the function dropEmptyImageDimensions from the neurobase package.

noneck = remove_neck(file_path,
    template.file = fslr::mni_fname(brain = TRUE, mm = 1),
    template.mask = fslr::mni_fname(mm = 1, brain = TRUE, mask = TRUE),
    verbose = FALSE
red = dropEmptyImageDimensions(noneck)
red <- readrpi(red)
ortho2(red, add.orient = TRUE)

Inhomogeneity correction

To correct the bias field signal we use the bias_correct function from the extrantsr package, which uses the N4 inhomogeneity correction.

t1_n4 = bias_correct(red,
                     correction = "N4",
                     outfile = tempfile(fileext = ".nii.gz"), retimg = FALSE
t1_n4 <- readrpi(t1_n4)

Malf registration

Once images are bias field corrected, we apply brain extraction using a form of multi-atlas label fusion (MALF). MALF uses a collection of previously labeled brain images (atlases), aligns the T1-weighted image to each atlas, and obtains a labeled T1-weighted image for each registration. This approach is implemented using the malf function from the malf.templates package, which includes the templates from the 2012 MICCAI Multi-Atlas Labeling Challenge.

timgs = mass_images(n_templates = 35)
ss = malf(infile = t1_n4,
          template.images = timgs$images,
          template.structs = timgs$masks,
          keep_images = FALSE,
          verbose = FALSE)

Perform skull stripping

To do this we use the preprocess_mri_within function from the extrantsr package. This function performs N4 bias correction, image registration (if multi- sequence data is given), skull stripping (estimating the brain mask if one is not supplied), and brain mask application to the registered images.

proc_outfile <- paste0("T1_Processed.nii.gz")
proc_outfile <- file.path(tempdir(),proc_outfile)
skull_ss <- preprocess_mri_within(
  files = t1_n4,
  outfiles = proc_outfile,
  correction = "N4",
  maskfile = ss,
  correct_after_mask = FALSE)
t1_ss <- readrpi(proc_outfile)
       col.y=alpha("red", 0.3),
       add.orient = TRUE)

Perform WhiteStripe intensity normalization

WhiteStripe intensity normalization can be implemented using the whitestripe andwhitestripe_norm functions from the WhiteStripe package.

ind = whitestripe(img = t1_ss, type = "T1", stripped = TRUE)$whitestripe.ind
Getting T1 Modes
Quantile T1 VOI
ws_t1 = whitestripe_norm(t1_ss, ind)

Perform segmentation

This is implemented here using the FAST function from FSL. FAST segments a 3D brain image into different tissue types. We will use the fast_nobias from the fslr package, which assumes that the the bias field was removed.

ss_tcs = fslr::fast_nobias(ws_t1,
                  verbose = TRUE)