# Load an example 4D brain image
example_4d_image <- read_vec(system.file("extdata", "global_mask_v4.nii", package = "neuroim2"))
# Create a NeuroVec object
neuro_vec <- NeuroVec(data = array(rnorm(64*64*32*10), dim = c(64, 64, 32, 10)),
space = NeuroSpace(dim = c(64, 64, 32,10),
origin = c(0, 0, 0),
spacing = c(3, 3, 4)))
dim(neuro_vec)
# Extract a single 3D volume (e.g., the first time point)
first_volume <- neuro_vec[[1]]
# Load an example 4D brain image
example_file <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2")
example_4d_image <- read_vec(example_file)
# Create a DenseNeuroVec object
dense_vec <- NeuroVec(data = example_4d_image@.Data,
space = space(example_4d_image))
print(dense_vec)
# Create a SparseNeuroVec object with a mask
mask <- array(runif(prod(dim(example_4d_image)[1:3])) > 0.5,
dim = dim(example_4d_image)[1:3])
sparse_vec <- NeuroVec(data = example_4d_image@.Data,
space = space(example_4d_image),
mask = mask)
print(sparse_vec)
Run the code above in your browser using DataLab