Title: | Read, Write and Manipulate High Dynamic Range Images |
---|---|
Description: | High Dynamic Range (HDR) images support a large range in luminosity between the lightest and darkest regions of an image. To capture this range, data in HDR images is often stored as floating point numbers and in formats that capture more data and channels than standard image types. This package supports reading and writing two types of HDR images; PFM (Portable Float Map) and OpenEXR images. HDR images can be converted to lower dynamic ranges (for viewing) using tone-mapping. A number of tone-mapping algorithms are included which are based on Reinhard (2002) "Photographic tone reproduction for digital images" <doi:10.1145/566654.566575>. |
Authors: | Mike Cheng [aut, cre, cph] |
Maintainer: | Mike Cheng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-10-29 06:55:01 UTC |
Source: | CRAN |
Clamp values outside the specified range
adj_clamp(arr, lo = -Inf, hi = Inf)
adj_clamp(arr, lo = -Inf, hi = Inf)
arr |
array or matrix |
lo |
low value. Values lower than this will be replaced with this value. Default: -Inf |
hi |
Values higher than this will be replaced with this value. Default: Inf |
adjusted array
Other array adjustment functions:
adj_gamma()
,
adj_infinite()
,
adj_rescale()
,
adj_shift_negatives_global()
,
adj_shift_negatives_local()
arr <- array(1:12, c(4, 3, 1)) arr adj_clamp(arr, 10, 20)
arr <- array(1:12, c(4, 3, 1)) arr adj_clamp(arr, 10, 20)
Adjust gamma
adj_gamma(arr, gamma = 1/2.2)
adj_gamma(arr, gamma = 1/2.2)
arr |
array or matrix |
gamma |
gamma correction factor. Default: 1/2.2 |
adjusted array
Other array adjustment functions:
adj_clamp()
,
adj_infinite()
,
adj_rescale()
,
adj_shift_negatives_global()
,
adj_shift_negatives_local()
arr <- array(1:12, c(4, 3, 1)) arr adj_gamma(arr)
arr <- array(1:12, c(4, 3, 1)) arr adj_gamma(arr)
Replace infinite values with the minimum/maximum of the finite values
adj_infinite(arr)
adj_infinite(arr)
arr |
array or matrix |
adjusted array
Other array adjustment functions:
adj_clamp()
,
adj_gamma()
,
adj_rescale()
,
adj_shift_negatives_global()
,
adj_shift_negatives_local()
arr <- array(c(-Inf, Inf, 1:10), c(4, 3, 1)) arr adj_infinite(arr)
arr <- array(c(-Inf, Inf, 1:10), c(4, 3, 1)) arr adj_infinite(arr)
Infinite values will be clamped to the limits
adj_rescale(arr, lo, hi)
adj_rescale(arr, lo, hi)
arr |
array or matrix |
lo , hi
|
limits |
adjusted array
Other array adjustment functions:
adj_clamp()
,
adj_gamma()
,
adj_infinite()
,
adj_shift_negatives_global()
,
adj_shift_negatives_local()
arr <- array(1:24, c(4, 3, 2)) arr adj_rescale(arr, 0, 1)
arr <- array(1:24, c(4, 3, 2)) arr adj_rescale(arr, 0, 1)
Shift all values such that the minimum of the array is 0
adj_shift_negatives_global(arr)
adj_shift_negatives_global(arr)
arr |
array or matrix |
adjusted array
Other array adjustment functions:
adj_clamp()
,
adj_gamma()
,
adj_infinite()
,
adj_rescale()
,
adj_shift_negatives_local()
arr <- array(c(-5, 1:23), c(4, 3, 2)) arr adj_shift_negatives_global(arr)
arr <- array(c(-5, 1:23), c(4, 3, 2)) arr adj_shift_negatives_global(arr)
Shift all values in a plane such that the minimum in every plane is 0
adj_shift_negatives_local(arr)
adj_shift_negatives_local(arr)
arr |
array or matrix |
adjusted array
Other array adjustment functions:
adj_clamp()
,
adj_gamma()
,
adj_infinite()
,
adj_rescale()
,
adj_shift_negatives_global()
arr <- array(c(-5, 1:23), c(4, 3, 2)) arr adj_shift_negatives_local(arr)
arr <- array(c(-5, 1:23), c(4, 3, 2)) arr adj_shift_negatives_local(arr)
This conversion is useful when preparing the data to summarise with
ggplot
.
array_to_df(arr)
array_to_df(arr)
arr |
array |
data.frame with 'x', 'y', 'z', 'channel' and 'value.' 'channel' will be the channel name if found, otherwise it is equivalent to 'z'.
arr <- array(1:24, dim = c(4, 3, 2)) array_to_df(arr)
arr <- array(1:24, dim = c(4, 3, 2)) array_to_df(arr)
write_exr()
The EXR file specification requires particular types to define the metadata for the image. This function helps define these metadata attributes.
exr_attrs( channels = NULL, compression = NULL, dataWindow = NULL, displayWindow = NULL, lineOrder = NULL, pixelAspectRatio = NULL, screenWindowCenter = NULL, screenWindowWidth = NULL, ... )
exr_attrs( channels = NULL, compression = NULL, dataWindow = NULL, displayWindow = NULL, lineOrder = NULL, pixelAspectRatio = NULL, screenWindowCenter = NULL, screenWindowWidth = NULL, ... )
channels |
|
compression |
|
dataWindow |
|
displayWindow |
|
lineOrder |
|
pixelAspectRatio |
|
screenWindowCenter |
|
screenWindowWidth |
|
... |
Other named parameters. value must be of class |
In the majority of cases for basic image output, there is no need to specify
anything with this function. write_exr()
will create mandatory
attributes required for image output.
Note that all values must be an object with class exr_type
. To
create these types, use exr_type$<TYPE>(...)
.
named list of attributes for writing EXR
exr_attrs(compression = exr_type$compression("ZIP"), name = exr_type$string("Render 032"))
exr_attrs(compression = exr_type$compression("ZIP"), name = exr_type$string("Render 032"))
This will extract attributes from any of EXR file.
exr_info(filename, verbosity = 0)
exr_info(filename, verbosity = 0)
filename |
EXR filename or connection |
verbosity |
verbosity. Default: 0 |
Named list of image attributes
filename <- system.file("image/rstats.exr", package = "picohdr") exr_info(filename)
filename <- system.file("image/rstats.exr", package = "picohdr") exr_info(filename)
This is a list of functions for creating EXR objects of a particular EXR type. Each function does checks for argument validity and calculates size information required for EXR output.
exr_type
exr_type
An object of class list
of length 23.
Refer to official OpenEXR documentation
# Create a v2f type exr_type$v2f(c(12.1, 2.3)) # Create an attribute exr_attrs(copyright = exr_type$string("mike"))
# Create a v2f type exr_type$v2f(c(12.1, 2.3)) # Create an attribute exr_attrs(copyright = exr_type$string("mike"))
Plot method for matrices and arrays
## S3 method for class 'array' plot(x, interpolate = TRUE, ...)
## S3 method for class 'array' plot(x, interpolate = TRUE, ...)
x |
matrix or array |
interpolate |
Default: TRUE |
... |
other arguments passed to plot() |
None.
filename <- system.file("image/rstats.pfm.bz2", package = "picohdr") image <- read_pfm(filename) image <- adj_gamma(image) plot(image)
filename <- system.file("image/rstats.pfm.bz2", package = "picohdr") image <- read_pfm(filename) image <- adj_gamma(image) plot(image)
Print 'exr_type' objects
## S3 method for class 'exr_type' print(x, ...)
## S3 method for class 'exr_type' print(x, ...)
x |
exr_type object |
... |
other arguments passed on to NextMethod |
None
bbox <- exr_type$box2i(0, 0, 1, 1) print(bbox)
bbox <- exr_type$box2i(0, 0, 1, 1) print(bbox)
Currently only single-part scanline images are supported (where the compression is one of NONE, ZIP or ZIPS).
read_exr(filename, verbosity = 0)
read_exr(filename, verbosity = 0)
filename |
EXR filename or connection |
verbosity |
Level of debugging output. Default: 0 (no debugging output) |
Numeric array with names along the third dimension. Each plane in the array corresponds to a channel in the EXR.
filename <- system.file("image/rstats.exr", package = "picohdr") images <- read_exr(filename) dimnames(images)[[3]] # Naively adjust one of the images for display im <- adj_rescale(images[, , 'dzdy'], lo = 0, hi = 1) plot(im)
filename <- system.file("image/rstats.exr", package = "picohdr") images <- read_exr(filename) dimnames(images)[[3]] # Naively adjust one of the images for display im <- adj_rescale(images[, , 'dzdy'], lo = 0, hi = 1) plot(im)
Read PFM image
read_pfm(filename)
read_pfm(filename)
filename |
PFM filename or connection object. If filename ends with 'xz', 'bz2' or 'gz' suffix then it will be uncompressed automatically. |
If input PFM file is grayscale, a 2D numeric array is returned. If PFM file represents RGB color values, a 3D numeric array is returned.
Other PFM functions:
write_pfm()
file <- system.file("image/rstats.pfm.bz2", package = "picohdr") arr <- read_pfm(file) arr[1:5, 1:5, ] # Tone-map the image, gamma correct and plot arr <- tm_reinhard_basic(arr) arr <- adj_gamma(arr) plot(arr)
file <- system.file("image/rstats.pfm.bz2", package = "picohdr") arr <- read_pfm(file) arr[1:5, 1:5, ] # Tone-map the image, gamma correct and plot arr <- tm_reinhard_basic(arr) arr <- adj_gamma(arr) plot(arr)
Tone mapping is a method for adapting an HDR image for display on a low dynamic range device. There are three included variants of Reinhard's global tone mapping operator.
tm_reinhard(arr) tm_reinhard_basic(arr) tm_reinhard_variant(arr)
tm_reinhard(arr) tm_reinhard_basic(arr) tm_reinhard_variant(arr)
arr |
array or matrix |
tm_reinhard()
[RGB] Reinhard's operator with a correction for the maximum luminance
tm_reinhard_basic()
[RGB images] Reinhard's operator applied equally to all colour channels
tm_reinhard_variant()
[RGB or Gray images] A combination of the above two methods
These functions are based on Reinhard (2002) "Photographic tone reproduction for digital images"
New array with adjusted color values
filename <- system.file("image", "rstats.pfm.bz2", package = "picohdr") image <- read_pfm(filename) image <- tm_reinhard_basic(image) image <- adj_gamma(image) plot(image)
filename <- system.file("image", "rstats.pfm.bz2", package = "picohdr") image <- read_pfm(filename) image <- tm_reinhard_basic(image) image <- adj_gamma(image) plot(image)
Write a numeric array as an EXR image
write_exr( arr, filename, pixel_type = c("half", "float", "uint"), channel_names = NULL, attrs = exr_attrs(), verbosity = 0 )
write_exr( arr, filename, pixel_type = c("half", "float", "uint"), channel_names = NULL, attrs = exr_attrs(), verbosity = 0 )
arr |
array representing image |
filename |
filename |
pixel_type |
one of 'half', 'float' or 'double'. Default: 'half' |
channel_names |
character vector. names of each plane in the array.
If |
attrs |
EXR attributes for image. Use |
verbosity |
verbosity. default: 0 |
None
orig_file <- system.file("image", "rstats.pfm.bz2", package = "picohdr") arr <- read_pfm(orig_file) exr_file <- tempfile(fileext = ".exr") write_exr(arr, exr_file)
orig_file <- system.file("image", "rstats.pfm.bz2", package = "picohdr") arr <- read_pfm(orig_file) exr_file <- tempfile(fileext = ".exr") write_exr(arr, exr_file)
Write a numeric array as PFM
write_pfm(arr, filename, endian = "little")
write_pfm(arr, filename, endian = "little")
arr |
numeric matrix or array (with 3 planes) |
filename |
filename or connection object. If filename ends with ".xz", '.bz2' or '.gz', then it will be automatically compressed. |
endian |
One of 'little' or 'big'. Default: 'little' |
None.
Other PFM functions:
read_pfm()
arr <- array(runif(10 * 30 * 3), dim = c(10, 30, 3)) write_pfm(arr, tempfile())
arr <- array(runif(10 * 30 * 3), dim = c(10, 30, 3)) write_pfm(arr, tempfile())