image_load: Loads an image into PIL format.

image_loadR Documentation

Loads an image into PIL format.

Description

Loads an image into PIL format.

Usage

image_load(
  path,
  color_mode = "rgb",
  target_size = NULL,
  interpolation = "nearest",
  keep_aspect_ratio = FALSE
)

Arguments

path

Path to image file.

color_mode

One of "grayscale", "rgb", "rgba". Default: "rgb". The desired image format.

target_size

Either NULL (default to original size) or tuple of ints ⁠(img_height, img_width)⁠.

interpolation

Interpolation method used to resample the image if the target size is different from that of the loaded image. Supported methods are "nearest", "bilinear", and "bicubic". If PIL version 1.1.3 or newer is installed, "lanczos" is also supported. If PIL version 3.4.0 or newer is installed, "box" and "hamming" are also supported. By default, "nearest" is used.

keep_aspect_ratio

Boolean, whether to resize images to a target size without aspect ratio distortion. The image is cropped in the center with target aspect ratio before resizing.

Value

A PIL Image instance.

Example

image_path <- get_file(origin = "https://www.r-project.org/logo/Rlogo.png")
(image <- image_load(image_path))
## <PIL.Image.Image image mode=RGB size=724x561>

input_arr <- image_to_array(image)
str(input_arr)
##  num [1:561, 1:724, 1:3] 0 0 0 0 0 0 0 0 0 0 ...

input_arr %<>% array_reshape(dim = c(1, dim(input_arr))) # Convert single image to a batch.
model |> predict(input_arr)

See Also

Other image utils:
image_array_save()
image_from_array()
image_smart_resize()
image_to_array()
op_image_affine_transform()
op_image_crop()
op_image_extract_patches()
op_image_map_coordinates()
op_image_pad()
op_image_resize()

Other utils:
audio_dataset_from_directory()
clear_session()
config_disable_interactive_logging()
config_disable_traceback_filtering()
config_enable_interactive_logging()
config_enable_traceback_filtering()
config_is_interactive_logging_enabled()
config_is_traceback_filtering_enabled()
get_file()
get_source_inputs()
image_array_save()
image_dataset_from_directory()
image_from_array()
image_smart_resize()
image_to_array()
layer_feature_space()
normalize()
pack_x_y_sample_weight()
pad_sequences()
set_random_seed()
split_dataset()
text_dataset_from_directory()
timeseries_dataset_from_array()
to_categorical()
unpack_x_y_sample_weight()
zip_lists()


rstudio/keras documentation built on April 22, 2024, 11:43 p.m.