Learn R Programming

ANTsR (version 1.0)

imagesToMatrix: Read Images into a Matrix

Description

Read images into rows of a matrix.

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.

See Also

matrixToImages, getMask

Examples

Run this code
# NOT RUN {
# make some simulated images and convert them to a matrix

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

# }

Run the code above in your browser using DataLab