Learn R Programming

rayimage (version 0.2.3)

add_image_overlay: Add Overlay

Description

Takes an RGB array/filename and adds an image overlay.

Usage

add_image_overlay(
  image,
  image_overlay = NULL,
  filename = NULL,
  preview = FALSE
)

Arguments

image

Image filename or 3-layer RGB array.

image_overlay

Default NULL. Either a string indicating the location of a png image to overlay over the image (transparency included), or a 4-layer RGBA array. This image will be resized to the dimension of the image if it does not match exactly.

filename

Default NULL. File to save the image to. If NULL and preview = FALSE, returns an RGB array.

preview

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

Value

3-layer RGB array of the processed image.

Examples

Run this code
# NOT RUN {
#Plot the dragon
plot_image(dragon)

#Add an overlay of a red semi-transparent circle:
circlemat = generate_2d_disk(min(dim(dragon)[1:2]))
circlemat = circlemat/max(circlemat)

#Create RGBA image, with a transparency of 0.5
rgba_array = array(0, dim=c(nrow(circlemat),ncol(circlemat),4))
rgba_array[,,1] = circlemat
rgba_array[,,4] = 0.5
dragon_clipped = dragon
dragon_clipped[dragon_clipped > 1] = 1
# }
# NOT RUN {
add_image_overlay(dragon_clipped, image_overlay = rgba_array, preview = TRUE)
# }

Run the code above in your browser using DataLab