timeserieswindow2matrix: Time-series image to matrix of time windows around...

Description Usage Arguments Value Author(s) Examples

View source: R/timeserieswindow2matrix.R

Description

Extract a matrix from a time-series image after applying a mask where each row is a space-time vector

Usage

1
2
3
4
5
6
7
8
timeserieswindow2matrix(
  timeseriesmatrix,
  mask,
  eventlist,
  timewindow,
  zeropadvalue = 0,
  spacing = NA
)

Arguments

timeseriesmatrix

Input timeseriesmatrix from timeseries2matrix

mask

Input mask of type 'antsImage' ... the mask will be replicated into a 4D image of length timewindow + zeropadvalue.

eventlist

time indices for the events to extract

timewindow

n-timepoints around each event, forward in time.

zeropadvalue

pads the mask by this amount fwd and bwd in time.

spacing

optional 4d spacing vector that will impact smoothing parameters

Value

Success – an R matrix of dimensions ntimewindow*sizeofnonzerovaluesinmask*nevents

Author(s)

Avants BB

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
img <- makeImage( c(10,10,10,50) , 0 )
mask <- as.antsImage( array( 1 , dim(img)[1:3] ) )
mat<-timeseries2matrix( img, mask )
mat <- timeserieswindow2matrix( mat , mask, c(1, 4, 5 ), 2, 0 )
print( dim(mat$eventmatrix) )
print( dim(mat$mask4d) )

##### another approach
dim4<-c( 20, 30, 10, 100 )
i1<-10:15
i2<-11:18
i3<-4:8
i4<-10:90
arr3d<-array(data = 0, dim = dim4[1:3] )
arr3d[i1,i2,i3]<-1
arr<-array(data = 0, dim =dim4 )
for ( t in i4 ) arr[,,,t]<-t
nois<-which( arr > 0 )
noisv<-rnorm( length(nois) )
arr[ nois ]<-arr[ nois ]+noisv*0.0
msk <- as.antsImage( arr3d )
img <- as.antsImage( arr )
mat<-timeseries2matrix( img, msk )
eanat<-sparseDecom(  mat, msk, sparseness=0.1, z=0.5,nvecs=2, its=5,cthresh=0, mycoption=1)
eanat2<-sparseDecom( mat,  sparseness=0.1,z=0.5,nvecs=2, its=5,cthresh=0, mycoption=1)
enomask<-eanat2$eigenanatomyimages[1,]
emask<-eanat$eigenanatomyimages[1,]
print( enomask[31:40] )
print(   emask[31:40] )

# same thing with event matrices ....
ttt<-timeserieswindow2matrix( mat, msk, c(20,40,60,70) , 6, 0 )
tte<-ttt$eventmatrix
eanat<-sparseDecom(  tte, ttt$mask4d, sparseness=-0.9, z=0.5,nvecs=2, its=5,cthresh=0, mycoption=1)
eanat2<-sparseDecom( tte,  sparseness=-0.9, z=0.5,nvecs=2, its=5,cthresh=0, mycoption=1)
enomask<-eanat2$eigenanatomyimages[,1]
# back to timematrix
tmat<-matrix( enomask,  nrow=6 )
# back to image
eimg<-antsImageClone( msk )
eimg[ msk == 1 ]<-tmat[1,]
# convert image space to evec space
emat<-eanat2$eigenanatomyimages
# convert emat to events FIXME this does not currently work
# eavent<-timeserieswindow2matrix( data.matrix(emat) , msk, 1 , 6, 0 )
# emask<-eavent$eventmatrix[1,]
#############################

neuroconductor-devel/ANTsR documentation built on April 1, 2021, 1:02 p.m.