arrays2tab: Table format to/from array format converters

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/auxiliary.r

Description

A list of 2D or 3D images X1, X2, ... can be stored in two popular formats.

These two functions provides convertion between these two formats.

Usage

1
2
arrays2tab(grids, XYlist, zero.rm=FALSE, EPSILON=0.1^6)
tab2arrays(grids, tab, default.val=0)

Arguments

grids

A list of monotonically increasing coordinate grids. For example, grids <- list(grid.x=seq(0, 100, 2), grid.y=exp(seq(1, 5, .2))).

XYlist

Lists of scans in array format.

tab

Scans in table format.

zero.rm

Should we remove voxels with constant zero values across all arrays? Default to FALSE.

EPSILON

If the absolute value of an entry is less than EPSILON it will be reset to zero. You can also use this to do simple background thresholding.

default.val

The value to be filled at blank voxels. Default to 0.

Details

arrays2tab() and tab2arrays() are roughly the inverse of each other. arrays2tab() is relative easy to implement and fast to run. but tab2arrays() is neither easy nor fast since it is hard to make an arbitrary shaped image without any particular ordering into a rectangular one. tab2arrays() assumes the first few columns of the table are coordinates. grids still need to be specified manually because 1. otherwise there might be places that should be in the grid but not detectable automatically; 2. it provides a safe guard against some common mistakes. If the first couple of columns have entirely different values (perhaps by a mistake), you may end up generating a 2M by 2M by 2M array —- it will eat all your memory and bring down your box in just seconds.

Value

Either a table containing both spatial coordinates and scans or a list of scans in array format.

Author(s)

Xing Qiu

See Also

rep.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Generate some FA maps in array format
N.x <- 8; N.y <- 8; N.z <- 3
for (i in 1:8) {
  FA.i <- array(rnorm(N.x*N.y*N.z), c(N.x,N.y,N.z))
  ## make some zeros and very small numbers
  FA.i[1:3, 1, ] <- 0; FA.i[1:3, 2, ] <- 0.00001
  assign(paste("FA",i,sep=""), FA.i)
}
grids <- list(2*(1:N.x)-1, 2*(1:N.y)-1, 2*(1:N.z)-1)
Xlist <- list(FA1, FA2, FA3, FA4); Ylist <- list(FA5, FA6, FA7, FA8)

tab1 <- arrays2tab(grids, Xlist) # dim(tab1) = c(N.x*N.y*N.z, 3+length(Xlist))
tab2 <- arrays2tab(grids, Xlist, zero.rm=TRUE) # 9 zeros are removed
# Now another 9 voxels with very small intensities are removed.
tab3 <- arrays2tab(grids, Xlist, zero.rm=TRUE, EPSILON=0.0001)

## Xlist2 is almost identical to Xlist except that those voxels with
## very small values are replaced by zeros
Xlist2 <- tab2arrays(grids, tab3) 

ygu427/iSPREADR documentation built on May 20, 2019, 4:37 p.m.