Get Cluster of certain size from spm_bwlabel

spm_bwlabel(
  infile,
  outfile = NULL,
  retimg = TRUE,
  k = NULL,
  topN = NULL,
  margin = NULL,
  binary = TRUE,
  spmdir = spm_dir(verbose = verbose, install_dir = install_dir),
  reorient = FALSE,
  verbose = TRUE,
  install_dir = NULL
)

Arguments

infile

input filename

outfile

output filename

retimg

Return the image instead of matlab output

k

Minimum cluster size needed

topN

Top number of clusters kept (used if k is NULL)

margin

Margin to loop over if wanted in 2D

binary

(logical) Should the result be binary or numbered with cluster.

spmdir

SPM directory (for MATLAB)

reorient

If retimg, then this argument is passed to readNIfTI

verbose

Print Diagnostics

install_dir

directory to download SPM12

Value

Output from run_matlab_script or nifti object, depending on retimg

Result from run_matlab_script

Note

Taken from http://en.wikibooks.org/wiki/SPM/How-to#How_to_remove_clusters_under_a_certain_size_in_a_binary_mask.3F

Examples

if (matlabr::have_matlab()) { d = rep(25, 3) arr = array(rbinom(prod(d), size = 1, prob = 0.5), dim = d) nim = oro.nifti::nifti(arr) res = spm_bwlabel(nim, k = 1, binary = FALSE, install_dir = tempdir()) tab = table(c(res)) tab out_arr = as(res, "array") }
#> cloning into '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmp13birO/spm12'... #> Receiving objects: 1% (68/6722), 23 kb #> Receiving objects: 11% (740/6722), 2964 kb #> Receiving objects: 21% (1412/6722), 3316 kb #> Receiving objects: 31% (2084/6722), 9469 kb #> Receiving objects: 41% (2757/6722), 10987 kb #> Receiving objects: 51% (3429/6722), 31461 kb #> Receiving objects: 61% (4101/6722), 36479 kb #> Receiving objects: 71% (4773/6722), 46980 kb #> Receiving objects: 81% (5445/6722), 70570 kb #> Receiving objects: 91% (6118/6722), 99259 kb #> Receiving objects: 100% (6722/6722), 131273 kb, done.
#> # K = 1
#> # Script is located at /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmp13birO/file9be853c26c6.m
#> Command run is:
#> matlab -nodesktop -nosplash -nodisplay -r "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmp13birO/file9be853c26c6.m'); catch err, disp(err.message); exit(1); end; exit(0);"
#> # Reading output file /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmp13birO/file9be874478c0e.nii
#>