dropImageDimension {oro.nifti}R Documentation

Drop Image Dimension

Description

Drops a dimension of an image that has one-dimension and sets respective values to 0 in pixdim or 1 in dim.

Usage

dropImageDimension(img, onlylast = TRUE, warn = TRUE)

drop_img_dim(img, onlylast = TRUE, warn = TRUE)

Arguments

img

nifti object

onlylast

is a logical variable (default = TRUE). Drop the dimension only if it is the last dimension. For example, if dim is 10x10x1x10 then no dimension is dropped, but if dim is 10x10x10x1 then it will be changed to 10x10x10.

warn

produces a text output if the number of dimensions is under three.

Value

Object of class nifti

Examples


nim <- nifti(array(rnorm(10^3), dim = rep(10, 3)))
nim2 <- nifti(array(rnorm(10^3), dim = c(10, 10, 1, 10)))
dropImageDimension(nim2)
dropImageDimension(nim2, onlylast = FALSE)
nim3 <- nifti(array(rnorm(10^3), dim = c(10, 10, 10, 1)))
dropImageDimension(nim3)
dropImageDimension(nim3, onlylast = FALSE) # the same as above
nim4 <- nifti(array(rnorm(10^3), dim = c(10, 10, 10, 1, 10)))
dim(nim4[,,,1,])
dim(nim4[,,,1,,drop=TRUE])
dropImageDimension(nim4)

nim5 <- nifti(array(rnorm(10^4), dim = c(1, 10, 10, 10, 1, 10)))
dropImageDimension(nim5)
dropImageDimension(nim5, onlylast = FALSE)

nim6 <- nifti(array(rnorm(10^3), dim = c(1, 10, 10, 10, 1, 1)))
dropImageDimension(nim6)
## Not run: 
## 27 scans of Colin Holmes (MNI) brain co-registered and averaged
## NIfTI two-file format
URL <- "http://imaging.mrc-cbu.cam.ac.uk/downloads/Colin/colin_1mm.tgz"
urlfile <- file.path(tempdir(), "colin_1mm.tgz")
download.file(URL, dest=urlfile, quiet=TRUE)
untar(urlfile, exdir=tempdir())
colin <- readNIfTI(file.path(tempdir(), "colin_1mm"))
dim(colin)
dim_(colin)
pixdim(colin)
# this will error
writeNIfTI(colin, filename = tempfile())
colin <- dropImageDimension(colin)
writeNIfTI(colin, filename = tempfile())

## End(Not run)

[Package oro.nifti version 0.11.4 Index]