NeuroSpace: Create a NeuroSpace Object

View source: R/neurospace.R

NeuroSpaceR Documentation

Create a NeuroSpace Object

Description

This function constructs a NeuroSpace object, which defines the spatial properties of a neuroimaging volume, including its dimensions, origin, spacing, axes, and coordinate transformation.

Usage

NeuroSpace(dim, spacing = NULL, origin = NULL, axes = NULL, trans = NULL)

Arguments

dim

An integer vector describing the dimensions of the image grid.

spacing

A numeric vector representing the real-valued voxel dimensions (e.g., in millimeters). If not provided, defaults to a vector of ones with the same length as 'dim'.

origin

A numeric vector representing the coordinate origin of the image space. If not provided, defaults to a vector of zeros with the same length as 'dim'.

axes

An AxisSet object representing the image axes ordering. If not provided, the default axes are determined based on the NIFTI standard (Left-Posterior-Inferior for 3D, or LEFT_RIGHT and POST_ANT for 2D).

trans

A matrix representing the coordinate transformation associated with the image space. If not provided, a default transformation is constructed based on the spacing and origin.

Details

The function performs several checks and computations:

  • It ensures that 'spacing' and 'origin' have appropriate lengths and values.

  • If 'trans' is not provided, it constructs a default transformation matrix.

  • It determines the appropriate axis set if not provided.

  • It creates a NeuroSpace object with the specified or computed properties.

The resulting NeuroSpace object encapsulates all the spatial information necessary to interpret and manipulate neuroimaging data.

Value

An instance of the NeuroSpace class.

Note

Users rarely need to create a new NeuroSpace instance directly, as it will almost always be created automatically using information stored in an image header. If an existing image object is available, its NeuroSpace instance can be easily extracted with the space method.

See Also

AxisSet-class for details on axis specifications. NeuroVol-class for volumetric data using NeuroSpace. space for extracting NeuroSpace from existing objects.

Examples

# Create a 3D NeuroSpace object
bspace_3d <- NeuroSpace(c(64, 64, 64), origin = c(0, 0, 0), spacing = c(2, 2, 2))
print(bspace_3d)
cat("Origin:", origin(bspace_3d), "\n")
cat("Axes:", axes(bspace_3d), "\n")
cat("Transformation matrix:\n")
print(trans(bspace_3d))

# Create a 2D NeuroSpace object
bspace_2d <- NeuroSpace(c(128, 128), spacing = c(1.5, 1.5))
print(bspace_2d)


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