NeuroSlice: Construct a NeuroSlice Object

View source: R/neuroslice.R

NeuroSliceR Documentation

Construct a NeuroSlice Object

Description

This function creates a NeuroSlice object, which represents a 2D slice of neuroimaging data with associated spatial information.

Usage

NeuroSlice(data, space, indices = NULL)

Arguments

data

A vector or matrix containing the slice data.

space

An instance of class NeuroSpace defining the spatial properties of the slice.

indices

Optional. A vector of linear indices used when data is a 1D vector. If provided, it specifies where the data should be placed in the 2D slice.

Details

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.

Value

A new instance of class NeuroSlice.

See Also

NeuroSpace-class for details on the spatial information. NeuroVol-class for 3D volumetric data.

Examples

# 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)


bbuchsbaum/neuroim2 documentation built on Nov. 3, 2024, 9:31 a.m.