knitr::opts_chunk$set(collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE) suppressPackageStartupMessages(library(neuroim2))
neuroim2 supports multiple representations for the same conceptual data:
3D volumes, 4D time-series, sparse masked data, memory-mapped arrays, and
file-backed access. Choosing the right representation is usually the biggest
practical decision you make up front.
This guide is the shortest path to that choice.
DenseNeuroVol or DenseNeuroVec when the data fits comfortably in memory and you want the simplest behavior.SparseNeuroVol or SparseNeuroVec when only a subset of voxels is meaningful and absent voxels should be treated as missing support rather than literal zeros.MappedNeuroVec when you want fast random access to an uncompressed NIfTI on disk without loading it all into memory.FileBackedNeuroVec when you want on-demand volume access from a file and can tolerate more I/O per access.NeuroHyperVec when the input is genuinely 5D.| Situation | Recommended backend | Why |
|:--|:--|:--|
| Small-to-moderate 3D image | DenseNeuroVol | simplest, lowest overhead |
| Small-to-moderate 4D fMRI series | DenseNeuroVec | easiest indexing and arithmetic |
| Masked analysis over a subset of voxels | SparseNeuroVec | stores only supported voxels |
| Large uncompressed NIfTI with random-access needs | MappedNeuroVec | memory mapping is efficient |
| Large file, on-demand volume access | FileBackedNeuroVec | no full materialization |
| 5D image | NeuroHyperVec | intended representation |
If the dataset fits in RAM, start here.
file_name <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2") vec <- read_vec(file_name) class(vec) dim(vec)
This gives you the most predictable behavior for:
If you only care about a subset of voxels, read the data through a mask and keep the representation sparse.
file_name <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2") mask_vol <- read_vol(file_name) > 0 svec <- read_vec(file_name, mask = mask_vol) class(svec) dim(svec) sum(mask(svec))
Use this when:
For large uncompressed NIfTI files, mmap mode gives efficient on-disk access.
file_name <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2") mvec <- read_vec(file_name, mode = "mmap") series(mvec, 1, 1, 1) sub_vector(mvec, 1:5)
Use this when:
filebacked mode is the safest on-disk choice when you want deferred access
without requiring the full dense object in memory.
file_name <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2") fbvec <- read_vec(file_name, mode = "filebacked") fbvec[[1]] sub_vector(fbvec, 1:3)
Use this when:
When the input is 5D, use read_image() or read_hyper_vec().
img5d <- read_image("some_5d_image.nii.gz") class(img5d)
If you are unsure:
read_vec() or read_vol().SparseNeuroVec only when a mask meaningfully reduces the support.mmap or filebacked when memory or I/O costs force the issue.vignette("Overview") for general orientationvignette("NeuroVector") for 4D workflowsvignette("Resampling") for spatial transformsvignette("regionOfInterest") for ROI and searchlight workflowsAny scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.