vwnrfs: voxelwise neighborhood random forest segmentation and...

Description Usage Arguments Value Author(s) Examples

View source: R/vwnrfs.R

Description

Represents feature images as a neighborhood and uses the features to build a random forest prediction from an image population

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
vwnrfs(
  y,
  x,
  labelmasks,
  rad = NA,
  nsamples = 8,
  ntrees = 500,
  asFactors = TRUE,
  reduceFactor = 1,
  ...
)

Arguments

y

list of training label images, can be a factor or numeric vector this can also be a regular old vector

x

a list of lists where each list contains feature images

labelmasks

a list of masks where each mask defines the image space for the given list. that is, the nth mask indexes the nth feature set. multi-label masks will try to balance sampling for each label.

rad

vector of dimensionality d define nhood radius

nsamples

(per subject to enter training)

ntrees

(for the random forest model)

asFactors

boolean - treat the y entries as factors

reduceFactor

integer factor by which to reduce (imaging) data resolution

...

arguments to pass to randomForest

Value

list a 4-list with the rf model, training vector, feature matrix and the random mask

Author(s)

Avants BB, Tustison NJ, Pustina D

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
mask<-makeImage( c(10,10), 0 )
mask[ 3:6, 3:6 ]<-1
mask[ 5, 5:6]<-2
ilist<-list()
lablist<-list()
masklist<-list()
inds<-1:5
scl<-0.33 # a noise parameter
for ( predtype in c("label","scalar") )
{
for ( i in inds ) {
  img<-antsImageClone(mask)
  imgb<-antsImageClone(mask)
  limg<-antsImageClone(mask)
  if ( predtype == "label") {  # 4 class prediction
    img[ 3:6, 3:6 ]<-rnorm(16)*scl+(i %% 4)+scl*mean(rnorm(1))
    imgb[ 3:6, 3:6 ]<-rnorm(16)*scl+(i %% 4)+scl*mean(rnorm(1))
    limg[ 3:6, 3:6 ]<-(i %% 4)+1  # the label image is constant
    }
    if ( predtype == "scalar") {
      img[ 3:6, 3:6 ]<-rnorm(16,1)*scl*(i)+scl*mean(rnorm(1))
      imgb[ 3:6, 3:6 ]<-rnorm(16,1)*scl*(i)+scl*mean(rnorm(1))
      limg<-i^2.0  # a real outcome
      }
    ilist[[i]]<-list(img,imgb)  # two features
    lablist[[i]]<-limg
    masklist[[i]] = mask
  }
  rfm<-vwnrfs( lablist , ilist, masklist[[1]], rad=c(2,2) ) # use single mask
  rfm<-vwnrfs( lablist , ilist, masklist, rad=c(2,2) )
  if ( predtype == "label" )
    print(  sum( rfm$tv != predict(rfm$rfm) ) )
  if ( predtype == "scalar" )
    print( cor(as.numeric(rfm$tv) , as.numeric(predict(rfm$rfm) ) ) )
} # end predtype loop

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