image_func: Apply function to each image

Description Usage Arguments Value Examples

View source: R/image_func.R

Description

This is a convenience function for applying magick functions that take an image as the first argument and return an image. It's fully vectorised, so you can set separate argument values for each image.

Usage

1
image_func(stimuli, func, ...)

Arguments

stimuli

list of class stimlist

func

the function or a string with the short name of the magick function (e.g., "blur" for image_blur()

...

arguments to pass to the function

Value

stimlist with new images

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
stimuli <- demo_stim()

# use magick::image_* functions
image_func(stimuli, "fill", color = "black", fuzz = 10,
           gravity = "north", location = "+0+10") %>%
  plot()

blur <- image_func(stimuli, "blur", 5, 3)
oilpaint <- image_func(stimuli, "oilpaint", radius = 5)
negate <- image_func(stimuli, "negate")
greenscreen <- image_func(stimuli, "transparent", color = "green", fuzz = 5)
colorize <- image_func(stimuli, "colorize", opacity = 50,
                       color = c("hotpink", "dodgerblue"))
sharpen <- image_func(stimuli, "contrast", sharpen = 1)

# load a logo image and superimpose it on each image
logo <- system.file("extdata/logo.png", package = "webmorphR") %>%
  magick::image_read() %>%
  magick::image_resize(100)
image_func(stimuli, "composite", logo, offset = "+10+10") %>% plot()

# use a self-defined function
testfunc <- function(image) {
  image # just return the image unprocessed
}
test <- image_func(stimuli, testfunc)

facelab/webmorph documentation built on April 11, 2021, 6:34 a.m.