dropImageDimension | R Documentation |
Drops a dimension of an image that has one-dimension and
sets respective values to 0 in pixdim
or 1 in dim
.
dropImageDimension(img, onlylast = TRUE, warn = TRUE) drop_img_dim(img, onlylast = TRUE, warn = TRUE)
img |
nifti object |
onlylast |
is a logical variable (default = |
warn |
produces a text output if the number of dimensions is under three. |
Object of class nifti
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.