Simple check to see if input is character or of class nifti and read in the header

check_nifti_header(x)

# S4 method for nifti
check_nifti_header(x)

# S4 method for character
check_nifti_header(x)

# S4 method for factor
check_nifti_header(x)

# S4 method for list
check_nifti_header(x)

# S4 method for array
check_nifti_header(x)

# S4 method for anlz
check_nifti_header(x)

# S4 method for ANY
check_nifti_header(x)

Arguments

x

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

Value

nifti object or character

Author

John Muschelli muschellij2@gmail.com

Examples

set.seed(5)
dims = rep(10, 4)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
check_nifti_header(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_header(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_header(arr))
tfile = tempimg(nim)
check_nifti_header(tfile)
#> 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_header(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
check_nifti_header(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_header(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_header(factor(tfile))
#> 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