Learn R Programming

IFC (version 0.1.1)

objectExtract: Object Extraction

Description

Extracts / Decompress objects stored in RIF or CIF Files.

Usage

objectExtract(ifd, param, verbose = FALSE, bypass = FALSE, ...)

Arguments

ifd

list of sub elements of IFD data information extracted by getIFD. This parameter can't be missing.

param

object of class `IFC_param`, containing extraction parameters defined by objectParam. This argument is not mandatory but it may allow to save time for repeated image export on same file. If this parameter is missing, objectExtract will use extra ... to pass arguments to objectParam to control object extraction. However, if 'param' is provided, '...' will be ignored.

verbose

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

bypass

whether to bypass checks on 'ifd' and 'param'. Default is FALSE.

...

other arguments to be passed to objectParam. If 'param' is not provided then '...' will be used to compute 'param'. /!\ If not any of 'fileName', 'info' can be found in '...' then attr(ifd, "fileName_image") will be used as 'fileName' input parameter to pass to objectParam.

Value

A list (for every extracted objects) of list (for every exported channels) depending on "export" parameter: -"matrix", a matrix when 'mode' is set to "raw" or "gray" OR an array when 'mode' == "rgb", -"base64", a data-uri string, -"file", an invisible file path corresponding to the location of exported file(s).

Examples

Run this code
# NOT RUN {
if(requireNamespace("IFCdata", quietly = TRUE)) {
  ## use a cif file
  file_cif <- system.file("extdata", "example.cif", package = "IFCdata")
  cif_offs <- getOffsets(fileName = file_cif, fast = TRUE)
  ## extract infomation
  info <- getInfo(fileName = file_cif, from = "analysis")
  ## retrieve number of objects stored
  nobj <- as.integer(info$objcount)
  ## randomly subset the offsets of at most 5 "img" objects
  sel = sample(0:(nobj-1), min(5, nobj))
  sub_offs <- subsetOffsets(cif_offs, objects = sel, image_type = "img")
  ## read IFDs from these "img" objects
  IFDs <- getIFD(fileName = file_cif, offsets = sub_offs)
  ## extract raw data of these"img" objects to matrix
  raw = objectExtract(ifd = IFDs, info = info, mode = "raw", 
                      export = "matrix")
  ## extract base64 "rgb" colorized version of these "img" objects to base64
  b64 = objectExtract(ifd = IFDs, info = info, mode = "rgb", 
                      export = "base64", base64_id = TRUE,
                      write_to = "example_%o_%c.png")
  ## use DisplayGallery to show the first "img" objects and play with ... extra parameters
  ## force_range, add_noise, selection, composite, see objectParam
  DisplayGallery(info = info, offsets = cif_offs, objects = sel,
                 base64_id = TRUE, write_to = "example_%o_%c.png",
                 force_range = c(FALSE,TRUE,FALSE,TRUE), add_noise = FALSE,
                 selection = c(1,2,4,6), composite = "1.7/4.3")
} 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.'))
}
# }

Run the code above in your browser using DataLab