Run STAPLE on a set of nifti images

staple_bin_img(x, set_orient = FALSE, verbose = TRUE, ...)

staple_multi_img(x, set_orient = FALSE, verbose = TRUE, ...)

Arguments

x

Character vector of filenames or list of arrays/images

set_orient

Should the orientation be set to the same if the images are niftiImages

verbose

print diagnostic messages

...

Additional arguments to staple_bin_mat

Value

A list similar to staple_bin_mat, but has a resulting image

Examples


n = 5
r = 1000
x = lapply(seq(n), function(i) {
   x = rbinom(n = r, size = 1, prob = 0.5)
   array(x, dim = c(10,10, 10))
 })
staple_out = staple_bin_img(x, set_orient = FALSE)
#> Reshaping images
#> Running STAPLE for binary matrix
#> iter: 1, diff: 0.331974475591742
#> iter: 10, diff: 0.000358032461720947
#> iter: 20, diff: 1.06043226870689e-05
#> iter: 30, diff: 3.19889546407381e-07
#> iter: 40, diff: 9.76275771336077e-09
#> iter: 50, diff: 2.99683944327001e-10
#> iter: 60, diff: 9.22273368786364e-12
#> iter: 70, diff: 2.84106072001578e-13
#> iter: 80, diff: 8.77076189453874e-15
#> iter: 90, diff: 3.33066907387547e-16
#> Convergence!
#> Creating output probability image/array
#> Creating output prior image/array
#> Creating label image (probability >= 0.5)
res = staple(x)
#> Reshaping images
#> There are 2 levels present
#> Removing elements where all raters agree
#> Making multiple, matrices. Hot-one encode
#> iter: 25, diff: 1.83832971645259e-06
#> iter: 50, diff: 2.99683944327001e-10
#> iter: 75, diff: 4.9960036108132e-14
#> Convergence!
#> Creating output probability images/arrays
#> Creating output label image/array
testthat::expect_equal(staple_out$sensitivity,
res$sensitivity)

x = lapply(x, RNifti::asNifti, internal = FALSE)
staple_img_out = staple_bin_img(x, set_orient = FALSE)
#> Reshaping images
#> All images are niftiImage ojects
#> Running STAPLE for binary matrix
#> iter: 1, diff: 0.331974475591742
#> iter: 10, diff: 0.000358032461720947
#> iter: 20, diff: 1.06043226870689e-05
#> iter: 30, diff: 3.19889546407381e-07
#> iter: 40, diff: 9.76275771336077e-09
#> iter: 50, diff: 2.99683944327001e-10
#> iter: 60, diff: 9.22273368786364e-12
#> iter: 70, diff: 2.84106072001578e-13
#> iter: 80, diff: 8.77076189453874e-15
#> iter: 90, diff: 3.33066907387547e-16
#> Convergence!
#> Creating output probability image/array
#> Creating output prior image/array
#> Creating label image (probability >= 0.5)
testthat::expect_equal(staple_out$sensitivity,
staple_img_out$sensitivity)
n = 5
r = 1000
x = lapply(seq(n), function(i) {
   x = rbinom(n = r, size = 5, prob = 0.5)
   array(x, dim = c(10,10, 10))
 })
staple_out = staple_multi_img(x, set_orient = FALSE)
#> Reshaping images
#> There are 6 levels present
#> Removing elements where all raters agree
#> Making multiple, matrices. Hot-one encode
#> iter: 25, diff: 4.74271146577721e-07
#> iter: 50, diff: 1.56245016924572e-11
#> iter: 75, diff: 7.7715611723761e-16
#> Convergence!
#> Creating output probability images/arrays
#> Creating output label image/array