# NOT RUN {
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, 0, sparseness=0.1,z=0.5,nvecs=2, its=5,cthresh=0, mycoption=1)
enomask<-eanat2$eigenanatomyimages[,1]
emask<-eanat$eigenanatomyimages[[1]][ msk == 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, 0, 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<-timeseries2matrix( eanat$eigenanatomyimages[[1]], msk )
# convert emat to events
eavent<-timeserieswindow2matrix( data.matrix(emat) , msk, 1 , 6, 0 )
emask<-eavent$eventmatrix[1,]
#############################
# }
Run the code above in your browser using DataLab