oasis_train_dataframe.RdThis function creates the training vectors from a single MRI study that has FLAIR, T1, T2, and PD volumes as well as binary masks of lesions. The function can create a brain mask for the data (or the user can supply a brain mask), can preprocess the data, and the user may supply already normalized data if they wish to use an alternative normalization method.
FLAIR volume of class nifti
T1 volume of class nifti
T2 volume of class nifti
PD volume of class nifti
gold standard lesion segmentation mask of class
nifti
brain mask of class nifti, if NULL a
brain mask will be created using fslbet
is a logical value that determines whether to call the
oasis_preproc function
and performs the necessary preprocessing steps for OASIS
is a logical value that determines whether
to perform z-score normalization of the image over the brain mask,
should be TRUE unless you train model
using an alternative normalization
vector of desired slices to train on, if NULL
then train over the entire brain mask
string value telling which orientation the training slices are specified in, can take the values of "axial", "sagittal", or "coronal"
is a logical value that indicates whether the preprocessed images should be returned
numeric indicating the number of cores to be used (no more than 4 is useful for this software implementation)
Sigmas used to smooth the data, default is 10,20
print diagnostic output
Should fslerode or oasis_erode be used
If return_preproc = FALSE the function returns a
data.frame for use with the oasis_training function.
Otherwise, the function returns a list containing:
a data.frame for use with the oasis_training function,
the FLAIR volume, the T1 volume, the T2 volume,
the PD volume, the brain mask for the subject, and the voxel selection mask.
library(neurobase)
dl_file = function(url) {
tfile = tempfile(fileext = ".nii.gz")
req <- httr::GET(url,
httr::write_disk(path = tfile))
httr::stop_for_status(req)
tfile
}
in_ci <- function() {
nzchar(Sys.getenv("CI"))
}
on_cran = function() {
identical(Sys.getenv("NOT_CRAN"), "false")
}
if (in_ci() || on_cran()) {
if (fslr::have.fsl() && require(httr)) {
mods = c("FLAIR", "T1W", "T2W", "consensus_gt", "brainmask")
base_url = file.path(
"https://raw.githubusercontent.com/muschellij2/open_ms_data",
"master/cross_sectional/coregistered/patient01/")
files = paste0(base_url, mods, ".nii.gz")
files = sapply(files, dl_file)
names(files) = mods
flair <- readnii(files["FLAIR"])
t1 <- readnii(files["T1W"])
t2 <- readnii(files["T2W"])
brain_mask <- readnii(files["brainmask"])
gold_standard = readnii(files["consensus_gt"])
oasis_preprocessed_data <- oasis_train_dataframe(flair, t1, t2,
brain_mask = brain_mask, gold_standard = gold_standard)
}
}