Simple check to see if input is character or of class nifti
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'nifti'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'character'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'factor'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'list'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'array'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = FALSE,
...
)
# S4 method for class 'anlz'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)
# S4 method for class 'ANY'
check_nifti(
x,
reorient = FALSE,
allow.array = FALSE,
fast = FALSE,
need_header = TRUE,
...
)character path of image or an object of class nifti, or array
(logical) passed to readnii
if the image
is to be re-oriented
(logical) Are array types allowed (TRUE) or should there be an error if the object is not character or class nifti.
if TRUE, then fast_readnii will be used
versus readnii if the files need to be read in.
if TRUE, then an image type with header information
will be returned. If not, then an array is fine. Used really only in
conjunction with allow.array
additional arguments to pass to readnii if relevant
nifti object or array if allow.array=TRUE and x is an array
x = nifti()
check_nifti(x)
#> 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 : 1 x 1 x 1 x 1
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
set.seed(5)
dims = rep(10, 4)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
check_nifti(nim)
#> 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 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
check_nifti(as.anlz(nim))
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
testthat::expect_error(check_nifti(arr, allow.array = FALSE))
tfile = tempimg(nim)
check_nifti(c(tfile, tfile))
#> [[1]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
#> [[2]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
check_nifti(list(tfile, tfile))
#> [[1]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
#> [[2]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
check_nifti(factor(c(tfile, tfile)))
#> [[1]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
#> [[2]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 4 (INT16)
#> Bits per Pixel : 16
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
check_nifti(RNifti::readNifti(tfile))
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 8 (INT32)
#> 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 x 10
#> Pixel Dimension : 1 x 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown