Learn R Programming

oro.nifti (version 0.4.3)

writeANALYZE-methods: writeANALYZE

Description

This function saves an Analyze-class object to a single binary file in Analyze format.

Usage

## S3 method for class 'anlz':
writeANALYZE(aim, filename, gzipped = TRUE, verbose = FALSE,
            warn = -1)

Arguments

aim
is an object of class anlz.
filename
is the path and file name to save the Analyze file pair (.hdr,img) without the suffixes.
gzipped
is a character string that enables exportation of compressed (.gz) files (default = TRUE).
verbose
is a logical variable (default = FALSE) that allows text-based feedback during execution of the function.
warn
is a number to regulate the display of warnings (default = -1). See options for more details.

Value

  • Nothing.

Details

The writeANALYZE function utilizes the internal writeBin and writeChar command to write information to a binary file.

References

Analyze 7.5 http://www.mayo.edu/bir/PDF/ANALYZE75.pdf

See Also

writeAFNI, writeNIfTI

Examples

Run this code
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,,]
img.anlz <- anlz(img) # create Analyze object

writeANALYZE(img.anlz, "test-anlz-image-uint8", verbose=TRUE)
## These files should be viewable in, for example, FSLview
## Make sure you adjust the min/max values for proper visualization
data <- readANALYZE("test-anlz-image-uint8", verbose=TRUE)
image(img.anlz, oma=rep(2,4), bg="white")
image(data, oma=rep(2,4), bg="white")
abs.err <- abs(data - img.anlz)
image(as(abs.err, "anlz"), zlim=range(img.anlz), oma=rep(2,4), bg="white")

## Loop through all possible data types
datatypes <- list(code=c(2, 4, 8, 16, 64),
                  name=c("uint8", "int16", "int32", "float", "double"))
equal <- vector("list")
for (i in 1:length(datatypes$code)) {
  fname <- paste("test-anlz-image-", datatypes$name[i], sep="")
  rm(img.anlz)
  img.anlz <- anlz(img, datatype=datatypes$code[i])
  writeANALYZE(img.anlz, fname)
  equal[[i]] <- all(readANALYZE(fname) == img)
}
names(equal) <- datatypes$name
unlist(equal)

Run the code above in your browser using DataLab