Tries to figure out the correct datatype for image. Useful for image masks - makes them binary if
datatyper(
img,
type_string = NULL,
datatype = NULL,
bitpix = NULL,
trybyte = TRUE,
warn = TRUE
)nifti object (or character of filename)
(NULL) character of datatype and bitpix. Supercedes
both datatype and bitpix. If specified
convert.datatype[[type_string]] and
convert.bitpix[[type_string]] will be used.
(NULL) character of datatype see
convert.datatype
(NULL) character of bitpix see
convert.bitpix
(logical) Should you try to make a byte (UINT8) if image in c(0, 1)?
Should a warning be issued if defaulting to FLOAT32?
object of type nifti
img = nifti(array(rnorm(10^3, sd = 1000), dim = rep(10, 3)))
rimg = round(img)
newnii(datatyper(rimg))
#> 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
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
rimg = datatyper(rimg, type_string= "FLOAT32")