nii2fst: Convert Nifti Image into FST Fast file

Description Usage Arguments Value Examples

Description

Convert Nifti Image into FST Fast file

Usage

1
2
3
4
5
nii2fst(file, fst_file = NULL, read_in = FALSE, ...)

check_image_dims(file)

.nii2fst(file, fst_file = NULL, read_in = FALSE, ...)

Arguments

file

a filename of the image

fst_file

output filename of FST file

read_in

Read in the FST file using fst::read_fst and return an FST object rather than a filename

...

additional arguments to fst::write_fst

Value

A list of the indices of the image and a file path of the FST file or FST data read if read_in = TRUE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
if (requireNamespace("oro.nifti", quietly = TRUE) &
    requireNamespace("neurobase", quietly = TRUE)) {
L = lapply(1:10, function(x) {
arr = oro.nifti::nifti(array(rnorm(50^3), dim = rep(50, 3)))
tfile = tempfile()
neurobase::writenii(arr, tfile)
tfile
})
arr = L[[1]]
nii2fst(arr)
nii2fst(arr, read_in = TRUE)
res = nii2fst(L)
res = nii2fst(L, read_in = TRUE)
ind = res$indices
grab_index = which(ind$dim1 >= 30 & ind$dim2 == 15 & ind$dim3 == 14)
mat = sapply(res$data, function(x) x[grab_index,])
}



# 4d exmample
if (requireNamespace("oro.nifti", quietly = TRUE) &
    requireNamespace("neurobase", quietly = TRUE)) {
L = lapply(1:10, function(x) {
arr = oro.nifti::nifti(array(rnorm(10^4), dim = rep(10, 4)))
tfile = tempfile()
neurobase::writenii(arr, tfile)
tfile
})
arr = L[[1]]
nii2fst(arr)
nii2fst(arr, read_in = TRUE)
res = nii2fst(L)
res = nii2fst(L, read_in = TRUE)
dim(res$data[[1]])
ind = res$indices
grab_index = which(ind$dim1 >= 30 & ind$dim2 == 15 & ind$dim3 == 14)
mat = sapply(res$data, function(x) x[grab_index,])
}

muschellij2/fstnii documentation built on June 14, 2019, 8:32 a.m.