Title: | Convert Images to Usable Color Schemes |
---|---|
Description: | A fast and adaptable tool to convert photos and images into usable colour schemes for data visualisation. Contains functionality to extract colour palettes from images, as well for the conversion of images between colour spaces. |
Authors: | Stuart Morrison [aut, cre] |
Maintainer: | Stuart Morrison <[email protected]> |
License: | GPL-3 |
Version: | 0.3.1.9000 |
Built: | 2025-02-21 06:16:57 UTC |
Source: | https://github.com/stuart-morrison/schemr |
Convert hex RGB values to Lab space.
hex_to_lab(hex, transformation = "sRGB", linear_func = NULL)
hex_to_lab(hex, transformation = "sRGB", linear_func = NULL)
hex |
A character vector containing hex representations of RGB colours. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of L, a and b colour space values.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) hex_to_lab(rgb_to_hex(data.frame(r = red, g = green, b = blue)))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) hex_to_lab(rgb_to_hex(data.frame(r = red, g = green, b = blue)))
Convert hexadecimal colours to RGB colour channels.
hex_to_rgb(hex)
hex_to_rgb(hex)
hex |
A character vector containing hex representations of RGB colours. |
A tibble
of red, green and blue colour channels.
hex_to_rgb(c("#5f9e3a"))
hex_to_rgb(c("#5f9e3a"))
Convert hex RGB values to XYZ space.
hex_to_xyz(hex, transformation = "sRGB", linear_func = NULL)
hex_to_xyz(hex, transformation = "sRGB", linear_func = NULL)
hex |
A character vector containing hex representations of RGB colours. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of X, Y and Z colour space values.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) hex_to_xyz(rgb_to_hex(data.frame(r = red, g = green, b = blue)))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) hex_to_xyz(rgb_to_hex(data.frame(r = red, g = green, b = blue)))
Convert HSL to HSV
hsl_to_hsv(hsl)
hsl_to_hsv(hsl)
hsl |
A dataframe or matrix with H, S and L colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
A tibble
of H, S and V colour channels. Hue is constant between colour spaces, while saturation differs.
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) L <- runif(n = 10) hsl_to_hsv(data.frame(h = H, s = S, l = L))
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) L <- runif(n = 10) hsl_to_hsv(data.frame(h = H, s = S, l = L))
Convert HSL to Lab
hsl_to_lab(hsl, transformation = "sRGB", linear_func = NULL)
hsl_to_lab(hsl, transformation = "sRGB", linear_func = NULL)
hsl |
A dataframe or matrix with H, S and L colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of L, a and b colour space values.
Convert HSL space into RGB space
hsl_to_rgb(hsl)
hsl_to_rgb(hsl)
hsl |
A dataframe or matrix with H, S and L colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
A tibble
of red, green and blue colour channels.
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) L <- runif(n = 10) hsl_to_rgb(data.frame(h = H, s = S, l = L))
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) L <- runif(n = 10) hsl_to_rgb(data.frame(h = H, s = S, l = L))
Convert HSL to XYZ
hsl_to_xyz(hsl, transformation = "sRGB", linear_func = NULL)
hsl_to_xyz(hsl, transformation = "sRGB", linear_func = NULL)
hsl |
A dataframe or matrix with H, S and L colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of X, Y and Z colour channels.
Convert HSV to HSL
hsv_to_hsl(hsv)
hsv_to_hsl(hsv)
hsv |
A dataframe or matrix with H, S and V colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
A tibble
of H, S and L colour channels. Hue is constant between colour spaces, while saturation differs.
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) V <- runif(n = 10) hsv_to_hsl(data.frame(h = H, s = S, v = V))
H <- sample(x = 0:360, size = 10, replace = TRUE) S <- runif(n = 10) V <- runif(n = 10) hsv_to_hsl(data.frame(h = H, s = S, v = V))
Convert HSV to Lab
hsv_to_lab(hsv, transformation = "sRGB", linear_func = NULL)
hsv_to_lab(hsv, transformation = "sRGB", linear_func = NULL)
hsv |
A dataframe or matrix with H, S and V colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of L, a and b colour space values.
Convert HSV to RGB
hsv_to_rgb(hsv)
hsv_to_rgb(hsv)
hsv |
A dataframe or matrix with H, S and V colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
A tibble
of red, green and blue colour channels.
Convert HSV to XYZ
hsv_to_xyz(hsv, transformation = "sRGB", linear_func = NULL)
hsv_to_xyz(hsv, transformation = "sRGB", linear_func = NULL)
hsv |
A dataframe or matrix with H, S and V colour channels located in the columns 1 to 3, respectively. H in degrees in [0, 360], S and L in [0, 1] |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of X, Y and Z colour channels.
Develop a usable colour palette form an image.
image_to_pallette( image_path, resize_factor = NULL, colour_space = "sRGB", rgb_to_linear_func = NULL, rgb_to_nonlinear_func = NULL, method = "slic", superpixel = 200, compactness = 20, verbose = TRUE, s = negDistMat(r = 2), summary_method = mean, ... )
image_to_pallette( image_path, resize_factor = NULL, colour_space = "sRGB", rgb_to_linear_func = NULL, rgb_to_nonlinear_func = NULL, method = "slic", superpixel = 200, compactness = 20, verbose = TRUE, s = negDistMat(r = 2), summary_method = mean, ... )
image_path |
A character path to the image to cluster. Reads images of type .png, .jpeg, .jpg, .tiff. |
resize_factor |
A numeric scalar that reduces (or increases) the size of the image before any processing. |
colour_space |
The colour space of the original image. The clustering is undertaken in the Lab space. This is an an option in |
rgb_to_linear_func |
The clustering is undertaken in the Lab space. This is a function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
rgb_to_nonlinear_func |
The clustering is undertaken in the Lab space. This is a function to convert linear RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
method |
From |
superpixel |
From |
compactness |
From |
verbose |
From |
s |
From |
summary_method |
Function to summarise colours in clustered superpixels. Defaults to |
... |
Other arguments to be passed to the apcluster algorithm. For the methods with signatures character,ANY and function,ANY, all other arguments are passed to the selected similarity function as they are; for the methods with signatures Matrix,missing and sparseMatrix,missing, further arguments are passed on to the apcluster methods with signatures Matrix,missing and dgTMatrix,missing, respectively. |
A schemr
object containing colour scheme colours and image properties and clusters.
Convert from Lab space into hex RGB colour values.
lab_to_hex(lab, transformation = "sRGB", linear_func = NULL)
lab_to_hex(lab, transformation = "sRGB", linear_func = NULL)
lab |
A dataframe or matrix with L, a and b colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A character vector with hex representations of RGB colour channels.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) lab_to_hex(rgb_to_lab(data.frame(r = red, g = green, b = blue)))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) lab_to_hex(rgb_to_lab(data.frame(r = red, g = green, b = blue)))
Convert Lab to HSL
lab_to_hsl(lab, transformation = "sRGB", linear_func = NULL)
lab_to_hsl(lab, transformation = "sRGB", linear_func = NULL)
lab |
A dataframe or matrix with L, a and b colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of H, S and L colour channels.
Convert Lab to HSv
lab_to_hsv(lab, transformation = "sRGB", linear_func = NULL)
lab_to_hsv(lab, transformation = "sRGB", linear_func = NULL)
lab |
A dataframe or matrix with L, a and b colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of H, S and V colour channels.
Convert from Lab space into RGB colour channels.
lab_to_rgb(lab, transformation = "sRGB", linear_func = NULL)
lab_to_rgb(lab, transformation = "sRGB", linear_func = NULL)
lab |
A dataframe or matrix with L, a and b colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of red, green and blue colour channels.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) lab_to_rgb(rgb_to_lab(data.frame(r = red, g = green, b = blue)))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) lab_to_rgb(rgb_to_lab(data.frame(r = red, g = green, b = blue)))
Convert from Lab space to XYZ colour channels.
lab_to_xyz(lab)
lab_to_xyz(lab)
lab |
A dataframe or matrix with L, a and b colour channels located in the columns 1 to 3, respectively. |
A tibble
of X, Y and Z colour channels.
l <- sample(x = 40:60, size = 10, replace = TRUE) a <- sample(x = -128:128, size = 10, replace = TRUE) b <- sample(x = -128:128, size = 10, replace = TRUE) lab_to_xyz(data.frame(l = l, a = a, b = b))
l <- sample(x = 40:60, size = 10, replace = TRUE) a <- sample(x = -128:128, size = 10, replace = TRUE) b <- sample(x = -128:128, size = 10, replace = TRUE) lab_to_xyz(data.frame(l = l, a = a, b = b))
Plot the colour palette
## S4 method for signature 'schemr' palette(value)
## S4 method for signature 'schemr' palette(value)
value |
A schemr class object |
No return value, calls a barplot of the colour pallette.
Plot the clustered image data
## S4 method for signature 'schemr,ANY' plot(x, y = NULL, ...)
## S4 method for signature 'schemr,ANY' plot(x, y = NULL, ...)
x |
A schemr class object |
y |
Not used, NULL |
... |
Other arguments to pass onto 'plot' |
No return value, calls a raster plot of the clustered image data.
Convert RGB colour channels to hex colour codes.
rgb_to_hex(rgb)
rgb_to_hex(rgb)
rgb |
A dataframe or matrix with red, green and blue colour channels located in the columns 1 to 3, respectively. Colour channel values should be between 0 and 255, inclusive. |
A character vector with hex representations of RGB colour channels.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_hex(data.frame(r = red, g = green, b = blue))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_hex(data.frame(r = red, g = green, b = blue))
Convert RGB space into HSL space
rgb_to_hsl(rgb)
rgb_to_hsl(rgb)
rgb |
A dataframe or matrix with red, green and blue colour channels located in the columns 1 to 3, respectively. Colour channel values should be between 0 and 255, inclusive. |
a tibble
of H, S and L colour channels.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_hsl(data.frame(r = red, g = green, b = blue))
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_hsl(data.frame(r = red, g = green, b = blue))
Convert RGB to HSV
rgb_to_hsv(rgb)
rgb_to_hsv(rgb)
rgb |
A dataframe or matrix with red, green and blue colour channels located in the columns 1 to 3, respectively. Colour channel values should be between 0 and 255, inclusive. |
A tibble
of H, S and V colour channels.
Convert from RGB colour channels to Lab space.
rgb_to_lab(rgb, transformation = "sRGB", linear_func = NULL)
rgb_to_lab(rgb, transformation = "sRGB", linear_func = NULL)
rgb |
A dataframe or matrix with red, green and blue colour channels located in the columns 1 to 3, respectively. Colour channel values should be between 0 and 255, inclusive. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of L, a and b colour space values.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_lab(data.frame(r = red, g = green, b = blue), transformation = "Adobe")
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_lab(data.frame(r = red, g = green, b = blue), transformation = "Adobe")
Convert from RGB colour channels to XYZ space.
rgb_to_xyz(rgb, transformation = "sRGB", linear_func = NULL)
rgb_to_xyz(rgb, transformation = "sRGB", linear_func = NULL)
rgb |
A dataframe or matrix with red, green and blue colour channels located in the columns 1 to 3, respectively. Colour channel values should be between 0 and 255, inclusive. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of X, Y and Z colour channels.
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_xyz(data.frame(r = red, g = green, b = blue), transformation = "Adobe")
red <- sample(x = 1:255, size = 10, replace = TRUE) green <- sample(x = 1:255, size = 10, replace = TRUE) blue <- sample(x = 1:255, size = 10, replace = TRUE) rgb_to_xyz(data.frame(r = red, g = green, b = blue), transformation = "Adobe")
Create the schemr class, which holds the palette and image data
image
An array of dimension (Image width) by (Image height) by (3 colour channels) that contains the data of the original image
clustered_image
An array of dimension (Image width) by (Image height) by (3 colour channels) that contains the data of the image with clustered colour blocks
palette
A character vector that contains the colours of the resulting colour palette
print(x)
Print the colour palette.
Convert from XYZ space into hex RGB colour values.
xyz_to_hex(xyz, transformation = "sRGB", linear_func = NULL)
xyz_to_hex(xyz, transformation = "sRGB", linear_func = NULL)
xyz |
A dataframe or matrix with X, Y and Z colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into non-linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A character vector with hex representations of RGB colour channels.
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_hex(data.frame(x = x, y = y, z = z))
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_hex(data.frame(x = x, y = y, z = z))
Convert XYZ to HSL
xyz_to_hsl(xyz, transformation = "sRGB", linear_func = NULL)
xyz_to_hsl(xyz, transformation = "sRGB", linear_func = NULL)
xyz |
A dataframe or matrix with X, Y and Z colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of H, S and L colour channels.
Convert XYZ to HSV
xyz_to_hsv(xyz, transformation = "sRGB", linear_func = NULL)
xyz_to_hsv(xyz, transformation = "sRGB", linear_func = NULL)
xyz |
A dataframe or matrix with X, Y and Z colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert RGB colour space into linear RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of H, S and V colour channels.
Convert from XYZ colour channels to Lab space.
xyz_to_lab(xyz)
xyz_to_lab(xyz)
xyz |
A dataframe or matrix with X, Y and Z colour channels located in the columns 1 to 3, respectively. |
A tibble
of L, a and b colour space values.
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_lab(data.frame(x = x, y = y, z = z))
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_lab(data.frame(x = x, y = y, z = z))
Convert from RGB colour channels to XYZ space.
xyz_to_rgb(xyz, transformation = "sRGB", linear_func = NULL)
xyz_to_rgb(xyz, transformation = "sRGB", linear_func = NULL)
xyz |
A dataframe or matrix with X, Y and Z colour channels located in the columns 1 to 3, respectively. |
transformation |
An option in |
linear_func |
A function to convert linear RGB colour space into RGB space. Used only if a custom transformation matrix is provided. Transformation skips if no function is provided under a user-defined transformation matrix. See: https://en.wikipedia.org/wiki/SRGB. |
A tibble
of red, green and blue colour channels.
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_rgb(data.frame(x = x, y = y, z = z))
x <- sample(x = 40:60, size = 10, replace = TRUE) y <- sample(x = 40:60, size = 10, replace = TRUE) z <- sample(x = 40:60, size = 10, replace = TRUE) xyz_to_rgb(data.frame(x = x, y = y, z = z))