Write Output as Analyze/NIfTI {dcemri} | R Documentation |
This function saves both the header information and multidimensional image array into a pair of binary files in Analyze format or a single binary file in NIfTI format.
write.analyze.img(fname, hdr, img, type, gzipped=TRUE, warn=-1) write.nifti.img(fname, hdr, img, type, gzipped=TRUE, warn=-1, ignoreQform=FALSE, ignoreSform=FALSE)
fname |
is the pathname to save the Analzye pair (.img and .hdr) or NIfTI file (.nii) without the suffix. |
hdr |
is the appropriate header object information. |
img |
is the multidimensional array of image data. |
type |
is a character string describing the image format. Valid character strings include:“uint1”, “uint8”, “int16”, “int32”, “float32”, “float64”. |
gzipped |
is a character string that enables exportation of
compressed (.gz) files (default = TRUE ). |
warn |
is a number to regulate the display of warnings (default =
-1). See options for more details. |
ignoreQform |
is a logical variable (default = FALSE ) that
ignores any ‘qform’ infomration in the NIfTI header. |
ignoreSform |
is a logical variable (default = FALSE ) that
ignores any ‘sform’ infomration in the NIfTI header. |
Both functions utilize the internal writeBin
and
writeChar
command to write infromation to a binary file.
Current acceptable data types include
write.analyze.img
and write.nifti.img
return nothing.
Brandon Whitcher, Volker Schmid
Analyze 7.5 http://www.mayo.edu/bir/PDF/ANALYZE75.pdf
NIfTI-1 http://nifti.nimh.nih.gov/
norm <- dnorm(seq(-5, 5, length=32), sd=2) norm <- (norm-min(norm)) / max(norm-min(norm)) img <- outer(outer(norm, norm), norm) img <- round(255*img) img[17:32,,] <- 255 - img[17:32,,] X <- nrow(img) Y <- ncol(img) Z <- nsli(img) ## NIfTI nhdr <- make.hdr(X, Y, Z, 1, "INT", "nifti") ## Not run: write.nifti.img("test-image-int16", nhdr, img, "int16") ## These files should be viewable in, for example, FSLview ## Make sure you adjust the min/max values for proper visualization data <- read.img("test-image-int16.nii.gz") par(mfrow=c(6,6), mar=rep(0,4)) for (z in 1:32) image(img[,,z], zlim=range(img), col=grey(0:255/255), xlab="", ylab="", axes=FALSE) for (z in 1:32) image(data[,,z,1], zlim=range(img), col=grey(0:255/255), xlab="", ylab="", axes=FALSE) for (z in 1:32) image(abs(data[,,z,1] - img[,,z]), zlim=range(img), col=grey(0:255/255), xlab="", ylab="", axes=FALSE) ## End(Not run) ## Loop through all possible data types datatypes <- c("uint8", "int16", "int32", "float", "double") equal <- vector("list") for (x in 1:length(datatypes)) { fname <- paste("test-image-", datatypes[x], sep="") write.nifti.img(fname, nhdr, img, datatypes[x]) equal[[x]] <- all(drop(read.img(fname)) == img) } names(equal) <- datatypes unlist(equal) ## Analyze (datatypes are the same as NIfTI) hdr <- make.hdr(X, Y, Z, 1, "int16") equal <- vector("list") for (x in 1:length(datatypes)) { fname <- paste("test-analyze-image-", datatypes[x], sep="") write.analyze.img(fname, hdr, img, datatypes[x]) equal[[x]] <- all(drop(read.img(fname)) == img) } names(equal) <- datatypes unlist(equal)