The function returns the visual complexity of an image. Visual
complexity is calculated as 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.
As R
's built-in bmp
device creates (a) indexed instead of
True Color images and (b) creates files with different file sizes depending
on the operating system, the function relies on the magick
package
to write (and read) images.