Windows an image to min and max values and also changes cal_max and cal_min parameters

window_img(
  x,
  window = c(0, 100),
  replace = c("window", "missing", "zero"),
  ...
)

Arguments

x

is either a character name for the image or an object of class nifti

window

numeric of length 2 that gives min and max for window

replace

either "window" if the any values outside of c(min, max) are set to the min or max or "missing" for these to be set to NA

...

not used

Value

Object of class nifti

See also

Examples

  set.seed(5)
  dims = rep(10, 3)
  arr = array(rnorm(prod(dims)), dim = dims)
  nim = oro.nifti::nifti(arr)
  window_img(nim, window = c(1, 5))
#> NIfTI-1 format
#>   Type            : nifti
#>   Data Type       : 2 (UINT8)
#>   Bits per Pixel  : 8
#>   Slice Code      : 0 (Unknown)
#>   Intent Code     : 0 (None)
#>   Qform Code      : 0 (Unknown)
#>   Sform Code      : 0 (Unknown)
#>   Dimension       : 10 x 10 x 10
#>   Pixel Dimension : 1 x 1 x 1
#>   Voxel Units     : Unknown
#>   Time Units      : Unknown
  window_img(nim, window = c(1, 5), replace = "missing")
#> NIfTI-1 format
#>   Type            : nifti
#>   Data Type       : 2 (UINT8)
#>   Bits per Pixel  : 8
#>   Slice Code      : 0 (Unknown)
#>   Intent Code     : 0 (None)
#>   Qform Code      : 0 (Unknown)
#>   Sform Code      : 0 (Unknown)
#>   Dimension       : 10 x 10 x 10
#>   Pixel Dimension : 1 x 1 x 1
#>   Voxel Units     : Unknown
#>   Time Units      : Unknown
  tfile = tempimg(nim)
  window_img(tfile)
#> NIfTI-1 format
#>   Type            : nifti
#>   Data Type       : 16 (FLOAT32)
#>   Bits per Pixel  : 32
#>   Slice Code      : 0 (Unknown)
#>   Intent Code     : 0 (None)
#>   Qform Code      : 0 (Unknown)
#>   Sform Code      : 0 (Unknown)
#>   Dimension       : 10 x 10 x 10
#>   Pixel Dimension : 1 x 1 x 1
#>   Voxel Units     : Unknown
#>   Time Units      : Unknown
  window_img(as.factor(tfile))
#> NIfTI-1 format
#>   Type            : nifti
#>   Data Type       : 16 (FLOAT32)
#>   Bits per Pixel  : 32
#>   Slice Code      : 0 (Unknown)
#>   Intent Code     : 0 (None)
#>   Qform Code      : 0 (Unknown)
#>   Sform Code      : 0 (Unknown)
#>   Dimension       : 10 x 10 x 10
#>   Pixel Dimension : 1 x 1 x 1
#>   Voxel Units     : Unknown
#>   Time Units      : Unknown
  arr = window_img(img_data(nim))
  rnim = RNifti::readNifti(tfile)
  window_img(rnim, window = c(1, 5))
#> Image array of mode "double" (9.1 Kb)
#> - 10 x 10 x 10 voxels
#> - 1 x 1 x 1 per voxel
  range(window_img(rnim, window = c(1, 5)))
#> [1] 1.000000 3.401872
  window_img(rnim, window = c(1, 5), replace = "missing")
#> Image array of mode "double" (9.1 Kb)
#> - 10 x 10 x 10 voxels
#> - 1 x 1 x 1 per voxel
  range(window_img(rnim, window = c(1, 5), replace = "missing"))
#> [1] NA NA