NeuroSlice | R Documentation |
This function creates a NeuroSlice object, which represents a 2D slice of neuroimaging data with associated spatial information.
NeuroSlice(data, space, indices = NULL)
data |
A vector or matrix containing the slice data. |
space |
An instance of class |
indices |
Optional. A vector of linear indices used when |
The function performs several checks and transformations:
It ensures that the provided space is 2-dimensional.
If indices
is not provided:
If data
is not 2D, it reshapes it to match the dimensions of space
.
It checks that the dimensions of data
match those of space
.
If indices
is provided:
It creates a zero matrix matching the dimensions of space
.
It places the data
values at the specified indices
in this matrix.
A new instance of class NeuroSlice
.
NeuroSpace-class
for details on the spatial information.
NeuroVol-class
for 3D volumetric data.
# Create a NeuroSpace object for a 64x64 slice
bspace <- NeuroSpace(c(64, 64), spacing = c(1, 1))
# Create random data for the slice
dat <- array(rnorm(64*64), c(64, 64))
# Construct a NeuroSlice object
bslice <- NeuroSlice(dat, bspace)
print(bslice)
# Using indices to create a sparse slice
sparse_data <- rnorm(100) # 100 non-zero values
sparse_indices <- sample(1:(64*64), 100) # 100 random positions
sparse_slice <- NeuroSlice(sparse_data, bspace, indices = sparse_indices)
print(sparse_slice)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.