Learn R Programming

webmorphR

The goal of webmorphR is to make the construction of image stimuli more reproducible, with a focus on face stimuli. While face stimuli used in research can often not be shared for ethical reasons, webmorphR allows you to share recipes for creating stimuli with code, increasing reproducibility and encouraging generalisability to new faces.

This development of this package was funded by ERC grant #647910 (KINSHIP).

Installation

You can (hopefully soon) install webmorphR from CRAN with:

install_packages("webmorphR")

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("debruine/webmorphR")

Use

The code below produces the following figure reproducibly, and can be applied to any set of original images.

Load images with psychomorph/webmorph templates or automatically delineate them. Use functions like resize(), align() and crop() to process the images reproducibly. Use webmorph functions to create composite or transformed faces. Use the plotting and labelling functions to create figures.

library(webmorphR)

# load 6 images from the smiling demo set
original <- demo_stim(dir = "smiling",
                      pattern = "002|013|030|064|094|099") 

# resize and delineate the images (using Face++)
# procrustes align and crop them to 80% size
processed <- original |>
  resize(0.5) |>
  auto_delin(smiling, model = "fpp106") |>
  align(procrustes = TRUE) |>
  crop(width = 0.8, height = 0.8, y_off = 0)

# rename and save individual images
processed |>
  rename_stim(prefix = "aligned_") |>
  write_stim(dir = "stimuli/smiling")

# average faces (using webmorph.org)
avg <- avg(processed)

# combine individual faces in a grid the same height as the average face
grid <- plot(processed, 
             ncol = 2, 
             external_pad = FALSE,
             maxheight = height(avg))

# draw template on the average face and add a label
tem_viz <- avg |>
  draw_tem() |>
  label(text = "Composite with Template",
        size = 30, location = "+0+10")

# combine the grid and tem_viz images and plot
c(grid, tem_viz) |> 
  plot(nrow = 1, maxwidth = 1500)

Helper packages

There are also two helper packages that contain large demo stimulus files or functions that require python and dlib.

devtools::install_github("debruine/webmorphR.stim")
devtools::install_github("debruine/webmorphR.dlib")

Copy Link

Version

Install

install.packages('webmorphR')

Monthly Downloads

33

Version

0.1.1

License

CC BY 4.0

Issues

Pull Requests

Stars

Forks

Maintainer

Lisa DeBruine

Last Published

June 2nd, 2022

Functions in webmorphR (0.1.1)

bounds

Get template bounds
col2lab

Color to Lab Conversion
align

Align templates and images
animate

Create an animated gif from a list of stimuli
change_lines

Change template lines
crop

Crop images and templates
centroid

Get center coordinates
crop_tem

Crop to template boundaries and pad
list_to_tbl

List format to table format
get_info

Get Information
c.stimlist

Combine stimlists
loop

Loop
get_point

Get Point Coordinates
height

Image heights
horiz_eyes

Make eyes horizontal
print.stim

Print stim
mirror

Mirror templates and images
plot_rows

Plot in rows
plot_stim

Plot stimuli
mlabel

Label with magick annotations
color_conv

Convert colors
rotated_size

Image size after rotation
same_tems

Check All Templates are the Same
mask

Mask Images with templates
gglabel

Label with ggplot annotations
greyscale

Make images greyscale
print.stimlist

Print stimlist
continuum

Morph between two images
delin

Manually delineate images
convert_tem

Convert templates
mask_oval

Apply an oval mask to images
resize

Resize stimuli
compare

Image Comparison
[.stimlist

Extract stimlist elements
tem_def

Get template definition
symmetrize

Symmetrize Images
[[<-.stimlist

Replace stimlist element
social_media_size

Social Media Image Sizes
rotate

Rotate templates and images
tem_text

Make text version of a template
squash_tem

Squash Template Points
demo_stim

Demo Stimuli
label

Label images
lab2rgb

Lab to RGB Conversion
features

Feature Points
draw_tem

Draw template
c.stim

Combine stim
plot.stim

Plot stim
message

WebmorphR Message
metrics

Image shape metrics
image_func_types

Possible functions
patch

Patch colour
get_imgs

Get Images into List
image_func

Apply a magick function to each image
pad

Pad images
format_size

Format file size
plot.stimlist

Plot stimuli
tems_to_array

Convert stimuli to array for geomorph
new_stim

Make a new stim
svgControlPoints

Get Control Points
svgBezier

Construct Bezier Curves from Template Points
readline_check

Check readline input
remove_tem

Remove templates
unique_names

Get unique names
new_stimlist

Make a new stimlist
viz_tem_def

Visualise a template definition
write_tps

Create a TPS file from a stimlist
require_tems

Require templates
read_img

Read image file
subset_tem

Subset template points
read_stim

Read stimuli
rep.stimlist

Repeat stim in a list
read_tem

Read tem file
rename_stim

Set stimulus names in a stimlist
procrustes_coords

Procrustes align templates
subset.stimlist

Subset Stimulus Lists
svgMoveTo

SVG Path Move
wm_opts

Set/get global webmorph options
svgQuadraticTo

SVG Path Quadratic Curve
width

Image widths
rep.stim

Repeat stim in a list
svgLineTo

SVG Path Line
svgCubicTo

SVG Path Quadratic Curve
to_size

Resize and crop/pad images to a specified size
webmorphR

webmorphR: Reproducible Face Stimuli
webmorph_up

Check if webmorph.org is available
trans

Transform Images
write_stim

Write images and templates to files
wm_opts_defaults

WebmorphR default options
blank

Make blank images
avg

Average Images
OR

Piped OR
add_info

Add Information
as_ggplot

Convert stimuli to a ggplot
auto_delin

Auto-Delineation
as_stimlist

Convert list to stimlist
average_tem

Average templates