imagesToMatrix: Read Images into a Matrix

View source: R/imagesToMatrix.R

imagesToMatrixR Documentation

Read Images into a Matrix

Description

Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.

Usage

imagesToMatrix(imageList, mask)

Arguments

imageList

A character vector containing a list of image files to read, in order.

mask

An antsImage containing a binary mask, voxels in the mask are placed in the matrix.

Value

A matrix containing the masked data, the result of calling as.numeric(image, mask) on each input image.

Author(s)

Cook PA, Avants BB (C++ version)

See Also

matrixToImages, getMask

Examples



# make some simulated images and convert them to a matrix

n <- 2
tdir <- tempdir()
for (i in 1:n) {
  simimg <- as.antsImage(replicate(64, rnorm(64)))
  antsImageWrite(simimg, tempfile(fileext = ".mha"))
}
imageList <- list.files(tdir, pattern = ".mha", full.names = TRUE)
mask <- getMask(antsImageRead(imageList[1]))
mat <- imagesToMatrix(imageList, mask)
print(dim(mat))


stnava/ANTsR documentation built on April 16, 2024, 12:17 a.m.