kmeansSegmentation.Rd
k means image segmentation that is a wrapper around atropos
kmeansSegmentation(img, k, kmask = NA, mrf = 0.1, verbose = FALSE, ...)
img | input image |
---|---|
k | integer number of classes |
kmask | segment inside this mask |
mrf | smoothness, higher is smoother |
verbose | boolean |
... | additional arguments to pass to |
segmentation and probability images
This function will likely give different results on multiple runs.
fi<-antsImageRead( getANTsRData("r16") ,2) orig = antsImageClone(fi) fi<-n3BiasFieldCorrection(fi,4) seg<-kmeansSegmentation( fi, 3 ) seg2<-kmeansSegmentation( fi, 3 ) arr1 = as.array(seg$segmentation) arr2 = as.array(seg2$segmentation) testthat::expect_equal(arr1, arr2) set.seed(2) # set below for slower but numerically repeatable results # these should be set in .Renviron not by sys calls # Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1 ) orig <-antsImageRead( getANTsRData("r16") ,2) seg<-kmeansSegmentation( orig, 3 , use_random_seed = TRUE) seg2<-kmeansSegmentation( orig, 3, use_random_seed = TRUE ) arr1 = as.array(seg$segmentation) arr2 = as.array(seg2$segmentation) tab = table(arr1, arr2) tab#> arr2 #> arr1 0 1 2 3 #> 0 47118 0 0 0 #> 1 0 2383 0 0 #> 2 0 1 7357 0 #> 3 0 0 2 8675#> [1] FALSEseg<-kmeansSegmentation( orig, 3, use_random_seed = FALSE ) seg2<-kmeansSegmentation( orig, 3, use_random_seed = FALSE ) arr1 = as.array(seg$segmentation) arr2 = as.array(seg2$segmentation) tab = table(arr1, arr2) tab#> arr2 #> arr1 0 1 2 3 #> 0 47118 0 0 0 #> 1 0 2385 0 0 #> 2 0 0 7353 0 #> 3 0 0 0 8680