ExportToNumpy: Numpy Export

View source: R/ExportToNumpy.R

ExportToNumpyR Documentation

Numpy Export

Description

Exports IFC objects to numpy array [objects,height,width,channels]

Usage

ExportToNumpy(
  ...,
  objects,
  offsets,
  image_type = "img",
  size = c(64, 64),
  force_width = FALSE,
  display_progress = TRUE,
  python = Sys.getenv("RETICULATE_PYTHON"),
  dtype = c("uint8", "int16", "uint16", "double")[3],
  mode = c("raw", "gray")[1],
  export = c("file", "matrix")[2],
  write_to,
  overwrite = FALSE
)

Arguments

...

arguments to be passed to objectExtract with the exception of 'ifd' and 'bypass'(=TRUE).
/!\ If not any of 'fileName', 'info' and 'param' can be found in '...' then attr(offsets, "fileName_image") will be used as 'fileName' input parameter to pass to objectParam.

objects

integer vector, IDEAS objects ids numbers to use. This argument is not mandatory, if missing, the default, all objects will be used.

offsets

object of class 'IFC_offset'. This argument is not mandatory but it may allow to save time for repeated image export on same file.
If 'offsets' are not provided, extra arguments can also be passed with '...' to getOffsets.

image_type

type of desired object offsets. Either "img" or "msk". Default is "img".

size

a length 2 integer vector of final dimensions of the image, height 1st and width 2nd. Default is c(64,64).

force_width

whether to use information in 'info' to fill 'size'. Default is FALSE. When set to TRUE, width of 'size' argument will be overwritten.

display_progress

whether to display a progress bar. Default is TRUE.

python

path to python. Default is Sys.getenv("RETICULATE_PYTHON").
Note that numpy should be available in this python to allow export to ".npy" file, otherwise 'export' will be forced to "matrix".

dtype

desired arrays data-type. Default is "double". Allowed are "uint8", "int16", "uint16" or "double". If 'mode' is "raw", this parameter will be forced to "int16".

mode

(objectParam argument) color mode export. Either "raw", "gray". Default is "raw".

export

export format. Either "file", "matrix". Default is "matrix".
Note that you will need reticulate package installed to be able to export to ".npy" file, otherwise 'export' will be forced to "matrix".

write_to

used when 'export' is "file" to compute exported file name and type. Exported type will be deduced from this pattern. Allowed exported file extension is ".npy".
Placeholders, if found, will be substituted:
-%d: with full path directory
-%p: with first parent directory
-%e: with extension of (without leading .)
-%s: with shortname (i.e. basename without extension)
-%o: with objects (at most 10, will be collapse with "_", if more than one).
-%c: with channel_id (will be collapse with "_", if more than one, composite in any will be bracketed). A good trick is to use:
-"%d/%s_Obj[%o]_Ch[%c].npy", when 'export' is "file".

overwrite

whether to overwrite file or not. Default is FALSE.

Details

Please note that 'size' parameter has to be supplied and could not be set to (0,) when 'object' length is not equal to one
ExportToNumpy requires reticulate package, python and numpy installed to create ".npy" file.
If one of these is missing, 'export' will be set to "matrix". If 'param' is provided in '...', param$export <- "matrix", param$mode <- 'mode' and param$size <- 'size' and will be overwritten.

Value

Depending on 'export':
-"matrix", an array whose dimensions are [object, height, width, channel].
-"file", it invisibly returns path of ".npy" exported file.

Note

Arguments of objectExtract will be deduced from ExportToNumpy input arguments.


IFC documentation built on Sept. 14, 2023, 1:08 a.m.