crop: Crop images and templates

Description Usage Arguments Details Value Examples

View source: R/crop.R

Description

Remove or add margins to images and templates. Width, height, x_off and y_off can be set in pixels (> 2.0) or proportions (between 0.0 and 2.0). Cropping is anchored at the image center (or calculated template centroid if there is no image) unless x_off or y_off are set.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
crop(
  stimuli,
  width = 1,
  height = 1,
  x_off = NULL,
  y_off = NULL,
  fill = webmorph_options("fill"),
  patch = FALSE,
  squash = FALSE
)

Arguments

stimuli

list of class stimlist

width

width of cropped image in pixels or % (<5)

height

height of cropped image in pixels or % (<5)

x_off

x-offset in pixels or % (<1) (NULL horizontally centers cropped image)

y_off

y-offset in pixels or % (<1) (NULL vertically centers cropped image)

fill

background color if cropping goes outside the original image

patch

whether to use the patch function to set the background color

squash

whether to move template points outside the image boundaries inside the image

Details

Fill can be set to R color names (see colors()) or valid hex or rgb values. Patch can be set to TRUE (defaults to median color of top left 10-pixel square) or a list of arguments to the function patch() to set background from a patch of the image.

Value

stimlist with cropped tems and/or images

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
stimuli <- demo_stim()

# crop to 60% width and 80% height (centered)
stim_centered <- crop(stimuli, width = .60, height = .80)

# crop to upper right quadrant
urq <- crop(stimuli, .5, .5, x_off = .5, y_off = 0)

# crop 150% to add border with custom fill
borders <- crop(stimuli, 1.5, 1.5, fill = "hotpink")

# crop to 40% width and 40% height (centered) and add border
# points are squashed to image edges
squash <- crop(stimuli, width = .4, height = .4, squash = TRUE)

# take median color from a patch
bigger <- crop(stimuli, 1.2, 1.2, patch = c(100, 200, 1, 10))

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