extract_colours: Detect and extract dominant colours from an image

Description Usage Arguments Examples

View source: R/extract_colours.R

Description

This function downloads an image and extracts the dominant colours from it. The code is based on dsparks' gist (https://gist.github.com/dsparks/3980277).

Usage

1
2
extract_colours(url_img = "http://developer.r-project.org/Logo/Rlogo-1.png",
  num_col = 5, rsize = 100)

Arguments

url_img

URL of the image (can be PNG, JPG, JPEG, TIFF) or a local file. Can also be an EBImage "Image" object

num_col

Number of dominant colours to be extracted (default = 5)

rsize

Size to reduce original image to, for further processing. This is the size, in pixels, for the largest dimension, from which colours are extracted. Please be careful with this option, as setting it too high can result in an extremely large processing time (or even running out of physical memory).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#Example 1a - Using the R logo to create a 5-colour palette
pal_r <- extract_colours("http://developer.r-project.org/Logo/Rlogo-1.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_r, main = "Palette based on R Logo")
hist(Nile, breaks = 5, col = pal_r, main = "Palette based on R Logo")

#Example 1b - Using the Kill Bill poster to create a 5-colour palette
pal_kb <- extract_colours("http://www.moviegoods.com/Assets/product_images/1010/477803.1010.A.jpg")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_kb, main = "Palette based on Kill Bill")
hist(Nile, breaks = 5, col = pal_kb, main = "Palette based on Kill Bill")

#Example 1c - Using Homer Simpson
pal_s <- extract_colours("http://haphappy.com/wp-content/uploads/2011/03/homerbeer2.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_s, main = "Palette based on Simpsons")
hist(Nile, breaks = 5, col = pal_s, main = "Palette based on Simpsons")

woobe/rPlotter documentation built on May 4, 2019, 9:48 a.m.