Description Usage Arguments Details Value Author(s) See Also Examples
A list of 2D or 3D images X1
, X2
, ... can be
stored in two popular formats.
ArrayA list of multi-dimensional arrays such that
X1[i,j,k]
is the value of the corresponding pixel/voxel. The
advantage of this format is that it is intuitive, enforces a
"rectangular" shape of the figure, which is a prerequisite of the
spatial kernel smoother used in this package. The actual spatial
location (coordinates) must be supplied separately, such as the
grids
list used by several other functions in this package.
TableA 2D table with each row represents a pixel/voxel. The first 2 or 3 columns store the spatial coordinates and each other column an image. The main advantage of this format is that it more flexible. The images don't have to be rectangular. You can omit the background of brain images altogether, resulting in more compact object. It is also easier to be exported to spreadsheet-like files. The fields package uses this format.
These two functions provides convertion between these two formats.
1 2 | arrays2tab(grids, XYlist, zero.rm=FALSE, EPSILON=0.1^6)
tab2arrays(grids, tab, default.val=0)
|
grids |
A list of monotonically increasing coordinate grids. For
example, |
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. |
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.
Either a table containing both spatial coordinates and scans or a list of scans in array format.
Xing Qiu
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.