writemulti: Tiff Writer

View source: R/writetiff.R

writemultiR Documentation

Tiff Writer

Description

Writes TIFF.

Usage

writemulti(
  image,
  write_to = raw(0),
  tags = list(list(tag = 270, typ = 2, map = "N/A"), list(tag = 306, typ = 2, map =
    "N/A")),
  as.rgb = FALSE,
  compression = TRUE,
  what = "int16",
  endianness = .Platform$endian,
  verbose = FALSE,
  verbosity = 1
)

Arguments

image

a matrix or array or representing the image:
-2D matrix [h,w] will be written as single grayscale [h,w] IFD (Image Field Directory),
-3D array [h,w,c] will be written as single IFD of multichannel [h,w,c] grayscale or RGB if rgb = TRUE,
-4D array [h,w,c,f] will be written as multiple (multiframe) IFD of multichannel [h,w,c] grayscale or RGB if rgb = TRUE,
with h=height, w=width, c=channel, f=frame.

write_to

file name or a raw vector. Default is raw(0).

tags

list of extra tags to be included to IFD. Expecting a list whose sub-elements are list containing:
-'tag' uint16_t, tag number, it should be [1-65535],
-'typ' uint16_t typ number it should be [1-12],
-'map' vector of values to write, it should not be empty and should be even for 'typ' 5 and 10.
Default provides an example as how to include "N/A" image description (tag=270) and date (tag=306)

as.rgb

whether to write image as RGB. Default is FALSE. It will be possible only for array where 3rd dimension length is 3.

compression

whether image should be lossless compressed with deflate algorithm. Default is FALSE.

what

bits mode used to store image. Default is "int16". Allowed are "uint8", "int8", "uint16", "int16", "uint32", "int32", "float" and "double".

endianness

The endian-ness ("big" or "little") of the return object. Default is .Platform$endian.
Endianness describes the bytes order of data stored within the files.

verbose

whether to display information (use for debugging purpose). Default is FALSE.

verbosity

quantity of information displayed when verbose is TRUE; 1: normal, 2: rich. Default is 1.

Value

It invisibly returns full path of exported file or a raw vector when write_to = raw(0) otherwise.

Examples

## Not run: 
if(requireNamespace("IFCdata", quietly = TRUE)) {
  ## use a cif file
  file_cif <- system.file("extdata", "example.cif", package = "IFCdata")
  ## extract image values from cif file
  RAW = ExtractImages_toMatrix(fileName = file_cif, mode = "raw", objects = 3,
                               force_width = FALSE, size = c(0,0))
  ## create multichannel tiff file
  file_tif = writemulti(image = array(unlist(RAW[[1]], use.names = FALSE, recursive = TRUE),
                                      dim = c(dim(RAW[[1]][[1]]), length(RAW[[1]]))),
                        write_to = tempfile(fileext = ".tif"))
  ## inspect exported file
  IFD = getIFD(file_tif)
  sapply(IFD[[1]]$tags, FUN = function(x) x)
  ## create multiframe tiff file
  file_tif = writemulti(image = array(unlist(RAW[[1]], use.names = FALSE, recursive = TRUE),
                                      dim = c(dim(RAW[[1]][[1]]), 1, length(RAW[[1]]))),
                        write_to = tempfile(fileext = ".tif"))
  ## inspect exported file
  IFDs = c(getIFD(file_tif),getIFD(file_tif, "all"))
  lapply(IFDs, FUN = function(i) sapply(i$tags, FUN = function(x) x))
} else {
  message(sprintf('Please run `install.packages("IFCdata", repos = "%s", type = "source")` %s',
                  'https://gitdemont.github.io/IFCdata/',
                  'to install extra files required to run this example.'))
}

## End(Not run)

gitdemont/IFC documentation built on Feb. 20, 2025, 12:55 a.m.