Reads an image from a file/array/matrix. From files, supports JPEG, PNG, TIFF, and EXR images.

ray_read_image(
  image,
  convert_to_array = FALSE,
  preview = FALSE,
  source_linear = NA,
  ...
)

Arguments

image

3-layer RGB/4-layer RGBA array, rayimg class, or filename of an image.

convert_to_array

Default TRUE. Whether to convert 2D B&W images/matrices to RGBA arrays.

preview

Default FALSE. If TRUE, it will display the image in addition to returning it.

source_linear

Default NA, automatically determined based on the image type. Whether the image source is linear data or sRGB. FALSE for matrices, arrays, and EXR files, true for all other formats (jpeg, png, and tiff).

...

Arguments to pass to either jpeg::readJPEG, png::readPNG, tiff::readTIFF, or libopenexr::read_exr().

Value

A rayimg RGBA array.

Examples

if(run_documentation()){
#Write as a png
tmparr = tempfile(fileext=".png")
ray_read_image(dragon) |>
 ray_write_image(tmparr)
ray_read_image(tmparr) |>
 plot_image()
}

if(run_documentation()){
#Write as a JPEG (passing quality arguments via ...)
tmparr = tempfile(fileext=".jpg")
ray_read_image(dragon) |>
 ray_write_image(tmparr, quality = 0.2)
ray_read_image(tmparr) |>
 plot_image()
}
#> Warning: JPEG decompression: Caution: quantization tables are too coarse for baseline JPEG

if(run_documentation()){
#Write as a tiff
tmparr = tempfile(fileext=".tiff")
ray_read_image(dragon) |>
 ray_write_image(tmparr)
ray_read_image(tmparr) |>
  plot_image()
}
#> Warning: TIFFReadDirectory: Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.


if(run_documentation()){
#Write as an exr
tmparr = tempfile(fileext=".exr")
ray_read_image(dragon) |>
 ray_write_image(tmparr)
ray_read_image(tmparr) |>
  plot_image()
}