Package {imagefluency}


Type: Package
Title: Image Statistics Based on Processing Fluency
Version: 1.1.0
Description: Get image statistics based on processing fluency theory. The functions provide scores for several basic aesthetic principles that facilitate fluent cognitive processing of images: contrast, complexity / simplicity, self-similarity, symmetry, and typicality. See Mayer & Landwehr (2018) <doi:10.1037/aca0000187> and Mayer & Landwehr (2018) <doi:10.31219/osf.io/gtbhw> for the theoretical background of the methods.
License: GPL-3
Encoding: UTF-8
URL: https://imagefluency.com, https://github.com/stm/imagefluency/, https://doi.org/10.5281/zenodo.5614665
BugReports: https://github.com/stm/imagefluency/issues/
Depends: R (≥ 4.1.0)
Imports: R.utils, readbitmap, pracma, magick, OpenImageR
Suggests: grid, ggplot2, scales, shiny, bslib, testthat, mockery, knitr, rmarkdown
Config/Needs/website: furrr, future, pbmcapply, tictoc, dplyr
Config/testthat/edition: 3
Collate: 'utils.R' 'complexity.R' 'contrast.R' 'typicality.R' 'symmetry.R' 'simplicity.R' 'self-similarity.R' 'fluency.R' 'imagefluency-package.R' 'imagefluencyApp.R'
VignetteBuilder: knitr
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-27 19:29:40 UTC; stefan
Author: Stefan Mayer ORCID iD [aut, cre]
Maintainer: Stefan Mayer <stefan@mayer-de.com>
Repository: CRAN
Date/Publication: 2026-11-27 19:50:02 UTC

imagefluency: Image Statistics Based on Processing Fluency

Description

logo

Get image statistics based on processing fluency theory. The functions provide scores for several basic aesthetic principles that facilitate fluent cognitive processing of images: contrast, complexity / simplicity, self-similarity, symmetry, and typicality. See Mayer & Landwehr (2018) doi:10.1037/aca0000187 and Mayer & Landwehr (2018) doi:10.31219/osf.io/gtbhw for the theoretical background of the methods.

Details

The main functions are:

Other helpful functions are:

Author(s)

Maintainer: Stefan Mayer stefan@mayer-de.com (ORCID)

Authors:

References

Mayer, S. & Landwehr, J. R. (2018). Quantifying Visual Aesthetics Based on Processing Fluency Theory: Four Algorithmic Measures for Antecedents of Aesthetic Preferences. Psychology of Aesthetics, Creativity, and the Arts, 12(4), 399–431. doi:10.1037/aca0000187

Mayer, S. & Landwehr, J. R. (2018). Objective measures of design typicality. Design Studies, 54, 146–161. doi:10.1016/j.destud.2017.09.004

See Also

Useful links:


.check_flag

Description

.check_flag is a helper function of the imagefluency package that checks whether an optional parameter is a single logical value (TRUE or FALSE). If that is not the case, a warning is thrown and the default value is returned.

Usage

.check_flag(
  x,
  name,
  default = FALSE,
  action = paste0("Automatically set to ", default, " ...")
)

Arguments

x

The value of the parameter.

name

The name of the parameter.

default

The default value that is used if the check fails.

action

Character string. End of the warning message.

Value

x if the check is passed, otherwise default.


.compl

Description

Returns the complexity of an image array / matrix or path.

Usage

.compl(img, algorithm, rotate)

Arguments

img

An array or matrix of numeric values or integer values, or the file path to the image.

algorithm

character. Which compression algorithm to use.

rotate

logical. Image rotation by 90 degrees?

Value

a numeric value (ratio compressed/uncompressed file size)


.compress_and_get_size

Description

Compresses an image and returns the compressed file size.

Usage

.compress_and_get_size(img, flname, algorithm, use_existing_bmp)

Arguments

img

An array or matrix of numeric values or integer values.

flname

Character string (file name without extension).

algorithm

Character string (which compression algorithm to use).

use_existing_bmp

Logical (use existing bmp file).

Value

a numeric value (compressed file size)


.contr

Description

Returns the RMS contrast of an image matrix.

Usage

.contr(img)

Arguments

img

A matrix of numeric values or integer values (normalized pixel intensity values).

Value

a numeric value (RMS contrast)


.img_names

Description

Returns the names of the images in a list: the names of the list elements, and img1, img2, ... for list elements without a name.

Usage

.img_names(imglist)

Arguments

imglist

A list of images.

Value

a character vector


.prepare_img

Description

.prepare_img is a helper function of the imagefluency package that checks whether the input is a valid image and returns the image in a standard form. All img_* functions use this function so that the same input is handled in the same way by every function.

Usage

.prepare_img(img)

Arguments

img

An object that needs to be checked.

Details

The following is checked: (1) the input is a matrix or an array (not, e.g., a vector or a data frame), (2) the values are numeric or integer, (3) the input is a matrix (grayscale image) or a 3-dimensional array with 1 (grayscale), 2 (grayscale with alpha channel), 3 (color), or 4 (color with alpha channel) layers in the third dimension, and (4) the input contains no missing or non-finite values. An alpha channel is removed with a warning.

Value

A list with the elements img (a matrix for grayscale images or a 3-dimensional array with 3 layers for color images) and type ("gray" or "rgb"). An error is thrown if the check fails.


.selfsim

Description

Returns the self-similarity of an image matrix as the degree to which the slope of the log-log power spectrum falls with power according to the value of 2.

Usage

.selfsim(img, full, raw, logplot, resize = TRUE)

Arguments

img

A matrix of numeric values or integer values, preferably of square size.

full

logical. Should the full frequency range be used for interpolation?

raw

logical. Should the raw value of the regression slope be returned?

logplot

logical. Should the log-log power spectrum of the image be plotted?

resize

logical. Should an image that is not square be resized to a square? If FALSE, the power spectrum of the original image is cropped to a square instead.

Value

a list with the self-similarity (self_sim), the number of spatial frequencies used for the regression (n_freq), and, if logplot = TRUE, the values for the log-log plot


.shift_axis

Description

.shift_axis shifts the mirror axis by xrange and returns the symmetries at each axis position by calling the .sym_mirror function.

Usage

.shift_axis(img, imgW, xrange)

Arguments

img

A matrix of numeric values or integer values.

imgW

Image width (numeric).

xrange

Shift range (numeric vector).

Value

a vector of mirror symmetry values


.shift_axis_fft

Description

Fast version of .shift_axis: returns the symmetries at each axis position (in the same order), but computes them for all axis positions at once instead of correlating the image halves separately for each position. The results equal those of .shift_axis up to floating-point error (about 1e-10).

Usage

.shift_axis_fft(img, imgW, xrange)

Arguments

img

A matrix of numeric values or integer values.

imgW

Image width (numeric).

xrange

Shift range (numeric vector).

Details

The correlation between the left image half and the mirrored right image half only requires the sums of the pixel values, of their squares, and of the products of each pixel with its mirrored counterpart. The first two are obtained from cumulative column sums. The sum of the products for all axis positions is the convolution of each image row with itself, which is computed via a fast Fourier transform.

Value

a vector of mirror symmetry values


.sym

Description

Calculates the mirror symmetry of an image by correlating image halves.

Usage

.sym(img, color, per_channel = TRUE, shift_range = 0.05, exact = FALSE)

Arguments

img

A matrix of numeric values or integer values.

color

logical. Color image?

per_channel

logical. Channel-wise maximum symmetry?

shift_range

numeric. Percentage of axis shift.

exact

logical. Compute the correlation directly for every position of the mirror axis?

Value

one numeric value as the symmetry (NA if there is no variation in the image halves)


.sym_max

Description

Returns the maximal mirror symmetry over all positions of the mirror axis. By default, the best position of the mirror axis is located via .shift_axis_fft and its symmetry is then computed directly via .sym_mirror. With exact = TRUE, the symmetry is computed directly for every position of the mirror axis via .shift_axis.

Usage

.sym_max(channels, imgW, xrange, exact)

Arguments

channels

A list with one matrix (grayscale image) or three matrices (color channels that share the position of the mirror axis).

imgW

Image width (numeric).

xrange

Shift range (numeric vector).

exact

logical. Compute the correlation directly for every position of the mirror axis?

Value

one numeric value as the symmetry (NA if the symmetry cannot be computed for any position of the mirror axis)


.sym_mirror

Description

sym_mirror returns the mirror symmetry of a grayscale image matrix. To this end, the left and right image halves are correlated.

Usage

.sym_mirror(img)

Arguments

img

A matrix of numeric values or integer values.

Value

a numeric value between 0 and 1 (NA if there is no variation in one of the image halves)


.typ

Description

Returns the typicality of a list of images as the correlation with the mean image.

Usage

.typ(imglist)

Arguments

imglist

A list of matrices with numeric values or integer values.

Value

a named matrix of numeric values (typicality scores)


.weight_channels

Description

Weighted average of the values of the three color channels (Rec. 601 weights), written so that equal values return their value exactly.

Usage

.weight_channels(red, green, blue)

Arguments

red, green, blue

Numeric vectors with the values of the red, green, and blue channel.

Value

a numeric vector


Image complexity

Description

img_complexity returns the complexity of an image via image compression. Higher values indicate higher image complexity.

Usage

img_complexity(imgfile, algorithm = "zip", rotate = FALSE)

Arguments

imgfile

Either a character string containing the path to the image file (or URL) or an image in form of a matrix (grayscale image) or array (color image) of numeric values representing the pre-loaded image (e.g. by using img_read()).

algorithm

Character string that specifies which image compression algorithm to use. Currently implemented are zip with deflate compression (default), jpg, gif, and png.

rotate

logical. Should the compressed file size of the rotated image also be computed? (see details)

Details

The function returns the visual complexity of an image. Visual complexity is calculated as the ratio between the compressed and uncompressed image file size. Preferably, the original image is an uncompressed image file.

The function takes the file path of an image file (or URL) or a pre-loaded image as input argument (imgfile) and returns the ratio of the compressed divided by the uncompressed image file size. Values can range between almost 0 (virtually completely compressed image, thus extremely simple image) and 1 (no compression possible, thus extremely complex image).

You can choose between different image compression algorithms. Currently implemented are zip with deflate compression (default), jpg, gif, and png. See Mayer & Landwehr (2018) for a discussion of different image compression algorithms for measuring visual complexity.

As most compression algorithms do not depict horizontal and vertical redundancies equally, the function includes an optional rotate parameter (default: FALSE). Setting this parameter to TRUE has the following effects: first, the image is rotated by 90 degrees. Second, a compressed version of the rotated image is created. Finally, the overall compressed image's file size is computed as the minimum of the original image's file size and the file size of the rotated image.

Pre-loaded images with pixel intensity values outside the range [0, 1] are normalized: values between 0 and 255 are divided by 255, any other range of values is rescaled to the range [0, 1]. An alpha channel is ignored. A grayscale image is treated as a color image with three identical color channels. Thus, the uncompressed file size is the same for grayscale and color images of the same size, which keeps the complexity scores of grayscale and color images comparable.

As R's built-in bmp device creates (a) indexed instead of True Color images and (b) files with different file sizes depending on the operating system, the function relies on the magick package to write (and read) images.

Value

a numeric value: the ratio of the compressed divided by the uncompressed image file size

References

Donderi, D. C. (2006). Visual complexity: A Review. Psychological Bulletin, 132, 73–97. doi:10.1037/0033-2909.132.1.73

Forsythe, A., Nadal, M., Sheehy, N., Cela-Conde, C. J., & Sawey, M. (2011). Predicting Beauty: Fractal Dimension and Visual Complexity in Art. British Journal of Psychology, 102, 49–70. doi:10.1348/000712610X498958

Mayer, S. & Landwehr, J. R. (2018). Quantifying Visual Aesthetics Based on Processing Fluency Theory: Four Algorithmic Measures for Antecedents of Aesthetic Preferences. Psychology of Aesthetics, Creativity, and the Arts, 12(4), 399–431. doi:10.1037/aca0000187

See Also

img_read, img_contrast, img_self_similarity, img_simplicity, img_symmetry, img_typicality

Examples


# Example image with high complexity: trees
trees <- img_read(system.file("example_images", "trees.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(trees)
#
# get complexity
img_complexity(trees)


# Example image with low complexity: sky
sky <- img_read(system.file("example_images", "sky.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(sky)
#
# get complexity
img_complexity(sky)


Image contrast

Description

img_contrast returns the RMS contrast of an image img. A higher value indicates higher contrast.

Usage

img_contrast(img)

Arguments

img

An image in form of a matrix or array of numeric values. Use e.g. img_read() to read an image file into R.

Details

The function returns the RMS contrast of an image img. The RMS contrast is defined as the standard deviation of the normalized pixel intensity values. A higher value indicates higher contrast. The image is automatically normalized if necessary (i.e., normalization into range [0, 1]): if the image contains values larger than 1, the pixel intensity values are assumed to range from 0 to 255 and are divided by 255. This is decided for the image as a whole, i.e., all color channels of an image are treated the same.

For color images, the weighted average between each color channel's values is computed.

Value

a numeric value (RMS contrast)

References

Peli, E. (1990). Contrast in complex images. Journal of the Optical Society of America A, 7, 2032–2040. doi:10.1364/JOSAA.7.002032

See Also

img_read, img_complexity, img_self_similarity, img_simplicity, img_symmetry, img_typicality

Examples

# Example image with relatively high contrast: berries
berries <- img_read(system.file("example_images", "berries.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(berries)
#
# get contrast
img_contrast(berries)

# Example image with relatively low contrast: bike
bike <- img_read(system.file("example_images", "bike.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(bike)
#
# get contrast
img_contrast(bike)


Image fluency scores for several images at once

Description

img_fluency computes the image fluency scores for several images at once and returns the results as a data frame with one row per image.

Usage

img_fluency(
  imgs,
  metrics = c("contrast", "self_similarity", "simplicity", "symmetry"),
  gray = FALSE,
  progress = interactive()
)

Arguments

imgs

Either a character vector with the paths to the image files (e.g., created by list.files() with full.names = TRUE) or a list of pre-loaded images (matrices or arrays of numeric values, e.g. by using img_read()).

metrics

Character vector that specifies which scores are computed. One or more of "contrast", "self_similarity", "simplicity", "symmetry", and "typicality". By default, all scores except typicality are computed (see details).

gray

logical. Should color images be converted into grayscale (using rgb2gray()) before the scores are computed? This speeds up the computation. (default: FALSE)

progress

logical. Should a progress bar be shown? (default: TRUE in interactive sessions)

Details

The function reads one image after the other and computes the requested scores with the respective functions of the package using their default settings:

Typicality is not computed by default (but can be added to metrics) for two reasons. First, typicality is not a characteristic of a single image, but of an image relative to all other images that are analyzed. Thus, the typicality scores change if images are added or removed. Second, all images have to be kept in memory at the same time to compute typicality, which might be a problem if you analyze many or large images. For all other scores, only one image is kept in memory at a time.

The function does not stop if an image file cannot be read or if a score cannot be computed for an image (e.g., symmetry for an image without any variation in one image half). Instead, the respective scores in the results are NA, and a warning at the end lists the images concerned. Warnings of the individual functions are not shown. Use the individual functions if you need other than the default settings or want to find out why a score could not be computed for an image.

Value

a data frame with one row per image (in the order of imgs). The first column filename contains the file names of the images (for a list of pre-loaded images: the names of the list; img1, img2, ... for images without a name). The other columns contain the scores and are named after metrics.

See Also

img_read, img_contrast, img_self_similarity, img_simplicity, img_symmetry, img_typicality

Examples

# paths to some of the example images
files <- system.file("example_images", c("rails.jpg", "sky.jpg", "trees.jpg"),
                     package = "imagefluency")

# contrast and symmetry scores of all images
img_fluency(files, metrics = c("contrast", "symmetry"))

# add typicality (of the images relative to each other)
img_fluency(files, metrics = c("contrast", "symmetry", "typicality"))


# all scores except typicality (default)
img_fluency(files)


Read bitmap image (bmp, jpg, png, tiff)

Description

Wrapper for readbitmap's read.bitmap function. The function currently allows reading in images in bmp, jpg / jpeg, png, or tif / tiff format.

Usage

img_read(path, ...)

Arguments

path

Path to the image file.

...

Additional parameters that are passed to read.bitmap and the underlying image reader packages.

Details

For details, see the read.bitmap documentation.

Value

Objects returned by read.bmp, readJPEG, readPNG, or readTIFF. See their documentation for details.

See Also

read.bitmap, read.bmp, readJPEG, readPNG, readTIFF

Examples

## Example image with high vertical symmetry: rails
rails <- img_read(system.file("example_images", "rails.jpg", package = "imagefluency"))

Image self-similarity

Description

img_self_similarity returns the self-similarity of an image (i.e., the degree to which the log-log power spectrum of the image falls with a slope of -2). Higher values indicate higher image self-similarity.

Usage

img_self_similarity(
  img,
  full = FALSE,
  logplot = FALSE,
  raw = FALSE,
  resize = TRUE
)

Arguments

img

An image in form of a matrix or array of numeric values, preferably of square size. If the input is not square, bilinear resizing to a square size is performed by default using the OpenImageR package (see parameter resize). Use e.g. img_read() to read an image file into R.

full

logical. Should the full frequency range be used for interpolation? (default: FALSE)

logplot

logical. Should the log-log power spectrum of the image be plotted? (default: FALSE)

raw

logical. Should the raw value of the regression slope be returned? (default: FALSE)

resize

logical. Should an image that is not square be resized to a square before the power spectrum is computed? If FALSE, the power spectrum is computed from the original image without resizing (see details). (default: TRUE)

Details

The function takes a (square) array or matrix of numeric or integer values representing an image as input and returns the self-similarity of the image. Self-similarity is computed via the slope of the log-log power spectrum using OLS. A slope near -2 indicates fractal-like properties (see Redies et al., 2007; Simoncelli & Olshausen, 2001). Thus, the value for self-similarity that is returned by the function is calculated as self-similarity = abs(slope + 2) * (-1). That is, the measure reaches its maximum value of 0 for a slope of -2, and any deviation from -2 results in negative values that are more negative the higher the deviation from -2. For color images, the weighted average between each color channel's values is computed (cf. Mayer & Landwehr, 2018).

By default, only the frequency range between 10 and 256 cycles per image is used for interpolation. Computation for the full range can be set via the parameter full = TRUE. Note that the highest frequency of an image is half of its (smaller) side length in pixels. For small images, the slope is therefore estimated from only a few frequencies (e.g., only from the frequencies 10 and 11 for an image with 22 pixels). The function throws a warning if the slope is estimated from fewer than 10 frequencies (i.e., for images with a side length of less than 38 pixels if full = FALSE).

Self-similarity cannot be computed for an image without any variation (e.g., an image with only one color; for color images, this applies to each color channel). In this case, the function returns NA and throws a warning.

If logplot is set to TRUE then a log-log plot of the power spectrum is additionally shown. If the package ggplot2 is installed the plot includes the slope of the OLS regression. Note that this option is currently only implemented for grayscale images.

It is possible to get the raw regression slope (instead of the transformed value which indicates self-similarity) by using the option raw = TRUE.

The power spectrum is computed for a square image. By default, an image that is not square is therefore first resized to a square (bilinear resizing of the longer image side to the length of the shorter side, so that the complete image content is kept). Note, however, that the interpolation smooths the image: fine details are attenuated more strongly than coarse structures, which makes the slope of the power spectrum steeper. The size of this effect depends on the image size and on the aspect ratio, and it is larger for small images. With resize = FALSE, the image is not resized. Instead, the power spectrum is computed from the complete, original image, and the same spatial frequencies (in cycles per image, in both the horizontal and the vertical direction) that the resized image would contain are analyzed. This also uses the complete image content but avoids the smoothing. For square images, resize has no effect.

Value

a numeric value (self-similarity)

Note

The function is inspired by Matlab's sfPlot (by Diederick C. Niehorster).

References

Mayer, S. & Landwehr, J. R. (2018). Quantifying Visual Aesthetics Based on Processing Fluency Theory: Four Algorithmic Measures for Antecedents of Aesthetic Preferences. Psychology of Aesthetics, Creativity, and the Arts, 12(4), 399–431. doi:10.1037/aca0000187

Redies, C., Hasenstein, J., & Denzler, J. (2007). Fractal-like image statistics in visual art: Similarity to natural scenes. Spatial Vision, 21, 137–148. doi:10.1163/156856807782753921

Simoncelli, E. P., & Olshausen, B. A. (2001). Natural image statistics and neural representation. Annual Review of Neuroscience, 24, 1193–1216. doi:10.1146/annurev.neuro.24.1.1193

See Also

img_read, img_contrast, img_complexity, img_simplicity, img_symmetry, img_typicality

Examples

# Example image with high self-similarity: romanesco
romanesco <- img_read(system.file("example_images", "romanesco.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(romanesco)
#
# get self-similarity
img_self_similarity(romanesco)

# Example image with low self-similarity: office
office <- img_read(system.file("example_images", "office.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(office)
#
# get self-similarity
img_self_similarity(office)

# the example images are not square: get self-similarity without resizing
img_self_similarity(office, resize = FALSE)


Image simplicity

Description

img_simplicity returns the simplicity of an image as 1 minus the complexity of the image. Higher values indicate higher image simplicity.

Usage

img_simplicity(imgfile, algorithm = "zip", rotate = FALSE)

Arguments

imgfile

Either a character string containing the path to the image file (or URL) or an image in form of a matrix (grayscale image) or array (color image) of numeric values representing the pre-loaded image (e.g. by using img_read()).

algorithm

Character string that specifies which image compression algorithm to use. Currently implemented are zip with deflate compression, jpg, gif, and png.

rotate

logical. Should the compressed file size of the rotated image also be computed? (see details)

Details

Image simplicity is calculated as 1 minus the ratio between the compressed and uncompressed file size (i.e., the compression rate). Values can range between 0 (no compression possible, thus extremely complex image) and almost 1 (virtually completely compressed image, thus extremely simple image). Different compression algorithms are implemented. For details, see img_complexity.

Value

a numeric value: 1 minus the ratio of compressed divided by uncompressed file size (i.e., the compression rate)

References

Donderi, D. C. (2006). Visual complexity: A Review. Psychological Bulletin, 132, 73–97. doi:10.1037/0033-2909.132.1.73

Forsythe, A., Nadal, M., Sheehy, N., Cela-Conde, C. J., & Sawey, M. (2011). Predicting Beauty: Fractal Dimension and Visual Complexity in Art. British Journal of Psychology, 102, 49–70. doi:10.1348/000712610X498958

Mayer, S. & Landwehr, J. R. (2018). Quantifying Visual Aesthetics Based on Processing Fluency Theory: Four Algorithmic Measures for Antecedents of Aesthetic Preferences. Psychology of Aesthetics, Creativity, and the Arts, 12(4), 399–431. doi:10.1037/aca0000187

See Also

img_read, img_complexity, img_contrast, img_self_similarity, img_symmetry, img_typicality

Examples


# Example image with low simplicity: trees
trees <- img_read(system.file("example_images", "trees.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(trees)
#
# get simplicity
img_simplicity(trees)

# Example image with high simplicity: sky
sky <- img_read(system.file("example_images", "sky.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(sky)
#
# get simplicity
img_simplicity(sky)


Image symmetry

Description

img_symmetry returns the vertical and horizontal mirror symmetry of an image. Higher values indicate higher image symmetry.

Usage

img_symmetry(img, vertical = TRUE, horizontal = TRUE, exact = FALSE, ...)

Arguments

img

An image in form of a matrix or array of numeric values. Use e.g. img_read() to read an image file into R.

vertical

logical. Should the vertical symmetry be computed? (default: TRUE)

horizontal

logical. Should the horizontal symmetry be computed? (default: TRUE)

exact

logical. Should the correlation be computed directly for every position of the mirror axis instead of locating the best position with a fast Fourier transform? This is considerably slower and only rarely leads to a (minimally) different result (see details). (default: FALSE)

...

Further options: shift_range to shift the mirror axis, per_channel to switch between a maximal per channel vs. per image symmetry (see details).

Details

The function returns the vertical and horizontal mirror symmetry of an image img. Symmetry values can range between 0 (not symmetrical) and 1 (fully symmetrical). If vertical or horizontal is set to FALSE then vertical or horizontal symmetry is not computed, respectively.

As the perceptual mirror axis is not necessarily exactly in the middle of a picture, the function estimates in a first step several symmetry values with different positions for the mirror axis. To this end, up to 5% (default) of the image width is cut off on the left or on the right side of the image (in the case of vertical symmetry; analogously for horizontal symmetry), and the symmetry of the remaining image part is computed. As the mirror axis is always in the middle of the remaining image part, cutting off 5% of the image width shifts the mirror axis by up to 2.5% of the image width to the right or to the left. In the second step, the overall symmetry score is computed as the maximum of the symmetry scores given the different mirror axes. See Mayer & Landwehr (2018) for details.

Advanced users can change the shift range with the optional parameter shift_range, which takes a numeric decimal between 0 and 1 as input (the maximum share of the image width that is cut off). The default is shift_range = 0.05 (i.e., 5%).

Symmetry cannot be computed if one of the image halves has no variation (e.g., an image half that has only one color; for color images, this applies to each color channel). In this case, the function returns NA for the respective symmetry and throws a warning. For color images with a color channel that has no variation (e.g., an image that only consists of black and red), consider converting the image into grayscale first (see rgb2gray).

For color images, the default is that first a maximal symmetry score (as explained above) is obtained per color channel (parameter per_channel = TRUE). Subsequently, a weighted average between each color channel's maximal score is computed as the image's overall symmetry. Advanced users can reverse this order by setting per_channel = FALSE. This results in first computing the weighted averages for each position of the mirror axis separately, and afterwards finding the maximal overall symmetry score.

To keep the computation fast, the best position of the mirror axis is located with a fast Fourier transform (FFT), which yields the symmetry values of all positions of the mirror axis at once. The symmetry score for this best position is then computed directly as the correlation between the two image halves. The result is the same as when the correlation is computed directly for every position of the mirror axis, unless the symmetry values of two positions are practically tied (difference smaller than about 1e-10). In this rare case, the score might differ by a correspondingly small amount. Setting exact = TRUE computes the correlation directly for every position of the mirror axis (the method used up to version 1.0.1), which avoids this at the expense of speed (the computation takes several times longer; for large images, more than ten times longer).

A perfectly symmetric image (i.e., the two image halves are identical mirror images of each other) always receives a score of exactly 1.

Value

a named vector of numeric values (vertical and horizontal symmetry)

References

Mayer, S. & Landwehr, J. R. (2018). Quantifying Visual Aesthetics Based on Processing Fluency Theory: Four Algorithmic Measures for Antecedents of Aesthetic Preferences. Psychology of Aesthetics, Creativity, and the Arts, 12(4), 399–431. doi:10.1037/aca0000187

See Also

img_read, img_complexity, img_contrast, img_self_similarity, img_simplicity, img_typicality

Examples

# Example image with high vertical symmetry: rails
rails <- img_read(system.file("example_images", "rails.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(rails)
#
# get symmetry
img_symmetry(rails)

# Example image with low vertical symmetry: bridge
bridge <- img_read(system.file("example_images", "bridge.jpg", package = "imagefluency"))
#
# display image
grid::grid.raster(bridge)
#
# get symmetry
img_symmetry(bridge)

# compute the correlation directly for every position of the mirror axis
# (slower)
img_symmetry(bridge, exact = TRUE)


Typicality of images relative to each other

Description

img_typicality returns the visual typicality of a list of images relative to each other. Higher values indicate larger typicality.

Usage

img_typicality(imglist, rescale = NULL)

Arguments

imglist

A list of arrays or matrices with numeric values. Use e.g. img_read() to read image files into R (see example).

rescale

numeric. Rescales the images prior to computing the typicality scores (by default, no rescaling is performed). Rescaling is performed by OpenImageR's resizeImage function (bilinear rescaling).

Details

The function returns the visual typicality of a list of image arrays or matrices imglist relative to each other. Values can range from -1 (inversely typical) through 0 (not typical) to 1 (perfectly typical). That is, higher absolute values indicate a larger typicality.

The typicality score is computed as the correlation of a particular image with the average representation of all images, i.e., the mean of all images. For color images, the weighted average between each color channel's values is computed. If the images have different dimensions they are automatically resized to the smallest height and width. If the list contains both grayscale and color images, the grayscale images are treated as color images with three identical color channels (with a warning).

Typicality cannot be computed for an image without any variation (e.g., an image with only one color). For such an image, the function returns NA and throws a warning.

Rescaling of the images prior to computing the typicality scores can be specified with the optional rescaling parameter (must be a numeric value). Most users won't need any rescaling and can use the default (rescale = NULL). See Mayer & Landwehr (2018) for more details.

Value

a matrix of numeric values (typicality scores) with one row per image and one column. The rows are named after the names of the input list (img1, img2, ... for images without a name). If the list contains fewer than two images, the scores are NA.

References

Mayer, S. & Landwehr, J. R. (2018). Objective measures of design typicality. Design Studies, 54, 146–161. doi:10.1016/j.destud.2017.09.004

See Also

img_read, img_contrast, img_complexity, img_self_similarity, img_simplicity, img_symmetry

Examples

# Example images depicting valleys: valley_green, valley_white
# Example image depicting fireworks: fireworks
valley_green <- img_read(
    system.file("example_images", "valley_green.jpg", package = "imagefluency")
  )
valley_white <- img_read(
    system.file("example_images", "valley_white.jpg", package = "imagefluency")
  )
fireworks <- img_read(
    system.file("example_images", "fireworks.jpg", package = "imagefluency")
  )
#
# display images
grid::grid.raster(valley_green)
grid::grid.raster(valley_white)
grid::grid.raster(fireworks)

# create image set as list
imglist <- list(fireworks, valley_green, valley_white)

# get typicality
img_typicality(imglist)

# named list: scores are labeled with the names of the images
img_typicality(list(fireworks = fireworks, valley_green = valley_green,
                    valley_white = valley_white))


RGB to Gray Conversion

Description

rgb2gray transforms colors from RGB space (red/green/blue) into a matrix of grayscale values.

Usage

rgb2gray(img)

Arguments

img

3-dimensional array of numeric or integer values

Details

The function takes a 3-dimensional array of numeric or integer values as input (img) and returns a matrix of grayscale values as output. The grayscale values are computed as GRAY = 0.299 * RED + 0.587 * GREEN + 0.114 * BLUE (as recommended in ITU-R BT.601). If the array has a fourth dimension (i.e., alpha channel), the fourth dimension is ignored.

Value

A matrix of grayscale values.

Examples

# construct a sample RGB image as array of random integers
imgRed <- matrix(runif(100, min = 0, max = 255), 10, 10)
imgGreen <- matrix(runif(100, min = 0, max = 255), 10, 10)
imgBlue <- matrix(runif(100, min = 0, max = 255), 10, 10)
imgColor <- array(c(imgRed, imgGreen, imgBlue), dim = c(10, 10, 3))

# convert to gray
img <- rgb2gray(imgColor)

Matrix or Array Rotation by 90 Degrees

Description

Matrix or Array Rotation by 90 Degrees

Usage

rotate90(img, direction = "positive")

Arguments

img

an array or a matrix

direction

The direction of rotation by 90 degrees. The value can be "positive" (default) or "negative". Aliases are "counterclockwise" and "clockwise", respectively.

Details

The function takes an array or matrix as input object (img) and returns the object rotated by 90 degrees. By default, the rotation is done in the mathematically positive direction (i.e., counterclockwise). Clockwise rotation (i.e., mathematically negative) can be specified by passing the value "negative" to the direction argument.

Value

an array or a matrix (rotated by 90 degrees)

Examples

# sample matrix
img <- matrix(1:6, ncol = 2)
img

rotate90(img) # counterclockwise
rotate90(img, direction = "negative") # clockwise

Interactive dashboard for imagefluency

Description

Launches a dashboard to interactively use the functions of the imagefluency package. The dashboard is built using the shiny package and provides a user-friendly interface for uploading images, analyzing them, and exporting the results. The dashboard supports multi-image uploads and side-by-side comparisons of image fluency scores.

Usage

run_imagefluency(max_images = 100)

Arguments

max_images

Integer. Maximum number of images that can be uploaded. Defaults to 100.

Examples

## Only run this example in interactive R sessions
if (interactive()) {
  run_imagefluency()

  # increase the maximum number of uploadable images to 150
  run_imagefluency(max_images = 150)
}