We build on the BRATS 2013 challenge to segment areas of the brain that have been damaged by stroke. We also refer to a more recent publication that implements a more complex version of what we do here.
We define a function that will help us simulate large, lateralized lesions on the fly.
library(ANTsR)
simLesion<-function( img, s , w, thresh=0.01, mask=NA, myseed )
{
set.seed(myseed)
img<-iMath(img,"Normalize")
if ( is.na(mask) ) mask<-getMask(img)
i<-makeImage( dim(img) , rnorm( length(as.array(img)) ) )
i[ mask==0 ]<-0
ni<-smoothImage(i,s)
ni[mask==0]<-0
i<-thresholdImage(ni,thresh,Inf)
i<-iMath(i,"GetLargestComponent")
ti<-antsImageClone(i)
i[i>0]<-ti[i>0]
i<-smoothImage(i,w)
i[ mask != 1 ] <- 0
i[ 1:(dim(img)[1]/2), 1:(dim(img)[2]-1) ]<-0
limg<-( antsImageClone(img) * (-i) %>% iMath("Normalize") )
return( list(limg=limg, lesion=i ) )
}
Now let’s apply this function to generate a test dataset.
Now let’s apply this function to generate a test dataset.
Create training data and map to the test subject. Note that a “real” application of this type would use cost function masking.
But let’s ignore that aspect of the problem here.
This gives us a subject with a “ground truth” segmentation.
Now we get a new subject and map to the space of the arbitrarily chosen reference space.
Now use these to train a model.
rad<-c(1,1) # fast setting
mr<-c(1,2,4,2,1) # multi-res schedule, U-style schedule
masks=list( getMask(seg), getMask(seg1) )
rfm<-mrvnrfs( list(seg,seg1) , list(list(ll$limg), list(ll1$limg) ),
masks, rad=rad, nsamples = 500, ntrees=1000, multiResSchedule=mr,
voxchunk=500 )
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
newrflist<-list()
temp<-mrvnrfs( list(seg,seg1) , list(list(ll$limg), list(ll1$limg) ),
masks, rad=rad, nsamples = 500, ntrees=1000, multiResSchedule=mr,
voxchunk=500 )
for ( k in 1:length( mr ) )
if ( length( rfm$rflist[[k]]$classes ) ==
length( temp$rflist[[k]]$classes ) )
newrflist[[k]]<-combine( rfm$rflist[[k]], temp$rflist[[k]] )
rfm$rflist<-newrflist
We apply the learned model to segment the new data.
Here is the ground truth.
Take a quick look at the lesion probability.
Now we compute the overlap.
The Dice overlap is 0.9216831. We might consider model selection as well where we do a quick estimate of lesion size based on the volume of left hemisphere csf. Then build the model from subjects that “match” with respect to the coarse amount of lesion.