Methods that act on the .Data field in a NIfTI/ANALYZE image but only on values inside a mask.

mask_vals(object, mask)

mask_vals(object, mask) <- value

# S4 method for nifti
mask_vals(object, mask) <- value

# S4 method for anlz
mask_vals(object, mask) <- value

# S4 method for array
mask_vals(object, mask) <- value

Arguments

object

is an object of class nifti or anlz.

mask

is an object of class nifti or anlz.

value

is the value to assign to the .Data field.

Examples

img = nifti(array(rnorm(10^3), dim = rep(10, 3)))
mask = img > 1.5
mask_vals(img, mask)
#>  [1] 1.606958 1.587421 1.639987 2.537115 1.862485 1.729261 2.139179 2.402836
#>  [9] 2.341337 1.604101 1.792343 1.895739 2.011536 2.015061 2.037684 1.501392
#> [17] 1.907294 1.541336 1.810500 1.731779 2.165307 1.530184 1.536322 2.151646
#> [25] 1.714155 2.197573 2.185153 1.756936 2.351888 2.710714 1.645982 2.087502
#> [33] 1.537226 2.265773 2.106504 2.403081 1.575780 2.395241 1.841757 2.434170
#> [41] 1.531446 2.242436 1.671718 1.816939 2.138648 2.358525 1.845185 1.849573
#> [49] 1.535087 2.095063 2.058937 2.297052 1.501804 1.754996 1.815978 1.592404
#> [57] 1.623367 1.919444 1.562332 1.877103 2.133997 2.561676 1.523764 1.805481
#> [65] 1.975068 1.803589 1.930555 1.632379 1.508631 2.354132 2.030999 1.952504
#> [73] 1.649233 1.667660 1.914847 2.873133 2.069829 1.688950 1.807531 2.223533
mask_vals(img, mask) = rep(4, sum(mask))
mask_vals(img, as(mask, "array")) = rep(4, sum(mask))
mask_vals(as(img, "array"), 
    as(mask, "array")) = rep(4, sum(mask))