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 nifti
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

# S4 method for character
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

# S4 method for factor
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

# S4 method for list
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

# S4 method for array
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = FALSE,
  ...
)

# S4 method for anlz
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

# S4 method for ANY
check_nifti(
  x,
  reorient = FALSE,
  allow.array = FALSE,
  fast = FALSE,
  need_header = TRUE,
  ...
)

Arguments

x

character path of image or an object of class nifti, or array

reorient

(logical) passed to readnii if the image is to be re-oriented

allow.array

(logical) Are array types allowed (TRUE) or should there be an error if the object is not character or class nifti.

fast

if TRUE, then fast_readnii will be used versus readnii if the files need to be read in.

need_header

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

Value

nifti object or array if allow.array=TRUE and x is an array

See also

Author

John Muschelli muschellij2@gmail.com

Examples

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