Learn R Programming

MRIaggr (version 1.1.5)

selectCoords: Extract spatial coordinates

Description

Extract the coordinates from a Carto3D or from a MRIaggr object.

Usage

"selectCoords"(object, coords=c("i","j","k"), num = NULL, format = "data.frame")
"selectCoords"(object, coords = c("i","j","k"), spatial_res = c(1,1,1), num = NULL, hemisphere = "both", subset = NULL, slice_var = "k", format = "data.frame")

Arguments

object
an object of class Carto3D or MRIaggr. REQUIRED.
coords
the coordinates that sould be extracted. Any of "i" "j" "k" or "index".
spatial_res
a dilatation factor for the coordinates. positive numeric vector of size 3.
num
the slices to extract. numeric vector or NULL.
hemisphere
the hemisphere to extract. character.
subset
the subset of observations to extract. positive integer vector or NULL leading to use all observations
slice_var
the type of slice to extract. "i" for sagittal, "j" for coronal and "k" for transverse. character.
format
the format of the output. Can be "vector", "matrix" or "data.frame".

Value

A "vector", matrix or a data.frame. In the latter two cases, each row corresponds to a voxel and each column to a coordinate.

Details

ARGUMENTS: Information about the num argument can be found in the details section of initNum.

Information about the hemisphere argument can be found in the details section of selectContrast.

FUNCTION: Each of the num, hemisphere and subset argument define a subset of the total set of observations. It is the intersection of all these three subsets that is extracted.

See Also

calcHemisphere to identify the hemispheres. allocHemisphere<- and allocContrast<- to allocate hemispheres obtained from an external source.

Examples

Run this code
#### 1- Carto3D method ####
## load nifti files and convert them to Carto3D
path.Pat1 <- system.file("nifti", package = "MRIaggr")
nifti.Pat1_TTP_t0 <- readMRI(file.path(path.Pat1, "TTP_t0"), format = "nifti")
Carto3D.Pat1_TTP_t0 <- constCarto3D(nifti.Pat1_TTP_t0, identifier = "Pat1", param = "TTP_t0")

## selection all coordinates
coords1 <- selectCoords(Carto3D.Pat1_TTP_t0)
dim(coords1)

## selection coordinates i and j from slices 1 to 3
coords2 <- selectCoords(Carto3D.Pat1_TTP_t0, num = 1:3, coords = c("i","j"))
dim(coords2)

#### 2- MRIaggr method ####
## load a MRIaggr object
data("MRIaggr.Pat1_red", package="MRIaggr")

## select all coordinates for all observations
coords <- selectCoords(MRIaggr.Pat1_red)
dim(coords)
head(coords)

## select coordinate i for slices 1 and 3
coords <- selectCoords(MRIaggr.Pat1_red, coords = "i", num = c(1,3))
dim(coords)
head(coords)

## select coordinate i for observations in the hemishere containing the lesion
coords <- selectCoords(MRIaggr.Pat1_red, hemisphere = "lesion", num = c(1,3))
dim(coords)
head(coords)

## select coordinate i for observations in the right hemisphere
coords <- selectCoords(MRIaggr.Pat1_red, hemisphere = "right", num = c(1,3))
dim(coords)
head(coords)

## select all coordinates and rescale them
coords <- selectCoords(MRIaggr.Pat1_red, spatial_res = c(1.875,1.875,6))
dim(coords)
head(coords)

## select coordinate i and j and return a matrix
coords <- selectCoords(MRIaggr.Pat1_red, format = "matrix")
is(coords)
head(coords)

Run the code above in your browser using DataLab