oasis_train_dataframe.Rd
This 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.
oasis_train_dataframe(flair, t1, t2, pd = NULL, gold_standard = NULL,
brain_mask = NULL, preproc = FALSE, normalize = TRUE, slices = NULL,
orientation = c("axial", "coronal", "sagittal"), return_preproc = FALSE,
cores = 1, sigma = c(10, 20), verbose = TRUE, eroder = c("fsl",
"oasis"))
flair | FLAIR volume of class |
---|---|
t1 | T1 volume of class |
t2 | T2 volume of class |
pd | PD volume of class |
gold_standard | gold standard lesion segmentation mask of class
|
brain_mask | brain mask of class |
preproc | is a logical value that determines whether to call the
|
normalize | is a logical value that determines whether
to perform z-score normalization of the image over the brain mask,
should be |
slices | vector of desired slices to train on, if |
orientation | string value telling which orientation the training slices are specified in, can take the values of "axial", "sagittal", or "coronal" |
return_preproc | is a logical value that indicates whether the preprocessed images should be returned |
cores | numeric indicating the number of cores to be used (no more than 4 is useful for this software implementation) |
sigma | Sigmas used to smooth the data, default is 10,20 |
verbose | print diagnostic output |
eroder | Should |
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)
}
}