Skip to contents

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

image_func(stimuli, func, ...)

Arguments

stimuli

list of stimuli

func

the function or a string with the short name of the magick function (see image_func_types())

...

arguments to pass to the function

Value

list of stimuli with new images

Details

These functions only affect the image, not the template. If a function changes the morphology of the image (e.g., "implode"), the template will not alter in the same way.

See also

Stimulus manipulation functions align(), crop_tem(), crop(), greyscale(), horiz_eyes(), mask_oval(), mask(), mirror(), pad(), resize(), rotate(), to_size()

Examples

stimuli <- demo_stim() |> resize(0.5)

# make a photographic negative version
image_func(stimuli, "negate")


# set different argument values for each image
image_func(stimuli, "implode", factor = c(0.2, -0.2))


# \donttest{
# other image functions
image_func(stimuli, "blur", 5, 3)

image_func(stimuli, "contrast", sharpen = 1)

image_func(stimuli, "oilpaint", radius = 5)

image_func(stimuli, "colorize", opacity = 50,
          color = c("hotpink", "dodgerblue"))


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


# use a self-defined function
testfunc <- function(image) {
  rot <- magick::image_rotate(image, 180)
  c(image, rot) |> magick::image_average()
}
image_func(stimuli, testfunc)

# }