Represents multiscale feature images as a neighborhood and uses the features to build a random forest segmentation model from an image population
mrvnrfs(y, x, labelmask, rad = NA, nsamples = 1, ntrees = 500,
multiResSchedule = c(4, 2, 1), asFactors = TRUE)
list of training labels. either an image or numeric value
a list of lists where each list contains feature images
a mask for the features (all in the same image space) the labelmask defines the number of parallel samples that will be used per subject sample. two labels will double the number of predictors contributed from each feature image.
vector of dimensionality d define nhood radius
(per subject to enter training)
(for the random forest model)
an integer vector defining multi-res levels
boolean - treat the y entries as factors
list a 4-list with the rf model, training vector, feature matrix and the random mask
# NOT RUN {
mask<-makeImage( c(10,10), 0 )
mask[ 3:6, 3:6 ]<-1
mask[ 5, 5:6]<-2
ilist<-list()
lablist<-list()
inds<-1:50
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
}
rad<-rep( 1, 2 )
mr <- c(1.5,1)
rfm<-mrvnrfs( lablist , ilist, mask, rad=rad, multiResSchedule=mr,
asFactors = ( predtype == "label" ) )
rfmresult<-mrvnrfs.predict( rfm$rflist,
ilist, mask, rad=rad, asFactors=( predtype == "label" ),
multiResSchedule=mr )
if ( predtype == "scalar" )
print( cor( unlist(lablist) , rfmresult$seg ) )
} # end predtype loop
# }
Run the code above in your browser using DataLab