Skip to contents

Converts a 3D array to a PIL Image instance.

Usage

image_from_array(x, data_format = NULL, scale = TRUE, dtype = NULL)

Arguments

x

Input data, in any form that can be converted to an array.

data_format

Image data format, can be either "channels_first" or "channels_last". Defaults to NULL, in which case the global setting config_image_data_format() is used (unless you changed it, it defaults to "channels_last").

scale

Whether to rescale the image such that minimum and maximum values are 0 and 255 respectively. Defaults to TRUE.

dtype

Dtype to use. NULL means the global setting config_floatx() is used (unless you changed it, it defaults to "float32"). Defaults to NULL.

Value

A PIL Image instance.

Example

img <- array(runif(30000), dim = c(100, 100, 3))
pil_img <- image_from_array(img)
pil_img

## <PIL.Image.Image image mode=RGB size=100x100>