All Projects โ†’ leonawicz โ†’ imgpalr

leonawicz / imgpalr

Licence: Unknown, MIT licenses found Licenses found Unknown LICENSE MIT LICENSE.md
R package for generating color palettes from arbitrary images.

Programming Languages

r
7636 projects
CSS
56736 projects

Projects that are alternatives of or similar to imgpalr

Materialdesigncolor
This project shows the color in material design
Stars: โœญ 55 (+25%)
Mutual labels:  color, color-palette
Colors App
๐ŸŽจ A PWA for copying values from popular color palettes. Supports HEX, RGB, and HSL formats.
Stars: โœญ 90 (+104.55%)
Mutual labels:  color, color-palette
Colorschemes.jl
colorschemes, colormaps, gradients, and palettes
Stars: โœญ 55 (+25%)
Mutual labels:  color, color-palette
R Color Palettes
Comprehensive list of color palettes available in r โค๏ธ๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ
Stars: โœญ 708 (+1509.09%)
Mutual labels:  color, color-palette
react-native-image-color-picker
Image color picker based on image source provided and return image different color palettes or average color palette
Stars: โœญ 25 (-43.18%)
Mutual labels:  color, color-palette
Kallewheel
A custom color wheel extension for Adobe Photoshop
Stars: โœญ 16 (-63.64%)
Mutual labels:  color, color-palette
Gvcci
color extraction to turn images into 16 color palettes
Stars: โœญ 86 (+95.45%)
Mutual labels:  color, color-palette
Colours
A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.
Stars: โœญ 3,101 (+6947.73%)
Mutual labels:  color, color-palette
colors
A gorgeous, accessible color system.
Stars: โœญ 748 (+1600%)
Mutual labels:  color, color-palette
Colors.lol
๐ŸŽจ Overly descriptive color palettes
Stars: โœญ 207 (+370.45%)
Mutual labels:  color, color-palette
hcv-color
๐ŸŒˆ Color model HCV/HCG is an alternative to HSV and HSL, derived by Munsell color system, usable for Dark and Light themes... ๐ŸŒˆ
Stars: โœญ 44 (+0%)
Mutual labels:  color, color-palette
quickpalette
๐Ÿƒโ€โ™€๏ธ๐ŸŽจ R package for quick extraction of color palettes from text and images
Stars: โœญ 24 (-45.45%)
Mutual labels:  color, color-palette
Chromacolorpicker
๐ŸŽจ An intuitive iOS color picker built in Swift.
Stars: โœญ 434 (+886.36%)
Mutual labels:  color, color-palette
Leonardo
Generate colors based on a desired contrast ratio
Stars: โœญ 973 (+2111.36%)
Mutual labels:  color, color-palette
Pickr
๐ŸŽจ Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
Stars: โœญ 3,759 (+8443.18%)
Mutual labels:  color, color-palette
Iconhandler
Tint you Icons, change the size, apply alpha color and set a position easily. ๐Ÿ‘“
Stars: โœญ 59 (+34.09%)
Mutual labels:  color, color-palette
word-color
Finds colors associated with a word, basically https://picular.co/
Stars: โœญ 39 (-11.36%)
Mutual labels:  color, color-palette
Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: โœญ 271 (+515.91%)
Mutual labels:  color, color-palette
Colorbook
๐ŸŽจ Color schemes for UI design - Optimized for foreground, background, border, etc. https://liyasthomas.github.io/colorbook
Stars: โœญ 148 (+236.36%)
Mutual labels:  color, color-palette
react-native-color-panel
React Native Color Panel Component for iOS and Android ๐Ÿณ๏ธโ€๐ŸŒˆ
Stars: โœญ 21 (-52.27%)
Mutual labels:  color, color-palette

imgpalr

Author: Matthew Leonawicz ORCID logo
License: MIT

Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed. Travis build status AppVeyor build status Codecov test coverage

CRAN status CRAN downloads Github Stars

Donate

The imgpalr package makes it easy to create color palettes from image files.

  • Choose the type of color palette to derive from an image: qualitative, sequential or divergent.
  • Quantiles of an image color distribution can be trimmed.
  • Near-black or near-white colors can be trimmed in RGB space independent of trimming brightness or saturation distributions in HSV space.
  • Creating sequential palettes also offers control over the order of HSV color dimensions to sort by.

Installation

Install the CRAN release of imgpalr with

install.packages("imgpalr")

Install the development version from GitHub with

# install.packages("remotes")
remotes::install_github("leonawicz/imgpalr")

Examples

The main function is image_pal. It accepts PNG, JPG, BMP or GIF (first frame) images either from disk or URL. It returns a vector of colors defining a palette based on the image and your other function arguments. You can also set plot = TRUE to plot a preview of the palette, which includes the source image thumbnail for visual reference.

The examples below offer some typical considerations to make when deriving a color palette from an arbitrary image.

Three palette types

In this first set of examples, divergent, qualitative and sequential palettes are generated from the same image and while varying some additional settings.

library(imgpalr)

set.seed(1)
x <- paste0(system.file(package = "imgpalr"), "/",
  c("blue-yellow", "purples", "colors"), ".jpg")

# Three palette types, one image
# A divergent palette
image_pal(x[1], type = "div",
  saturation = c(0.75, 1), brightness = c(0.75, 1), plot = TRUE)

# A qualitative palette
image_pal(x[1], type = "qual", bw = c(0.25, 0.9), plot = TRUE)

 # A sequential palette
image_pal(x[1], type = "seq", k = 2, saturation = c(0.75, 1),
  brightness = c(0.75, 1), seq_by = "hsv", plot = TRUE)

A dominant hue

In this test image, hue varies over a narrow range. A sequential palette is sensible here, but not necessarily best sorted by hue. Doing so does still show a perceivable order to the colors, but it is much more difficult to discern. Sorting the palette first by saturation or brightness makes a much better sequential palette in this case.

image_pal(x[2], type = "seq", seq_by = "hsv", plot = TRUE)

image_pal(x[2], type = "seq", seq_by = "svh", plot = TRUE)

image_pal(x[2], type = "seq", seq_by = "vsh", plot = TRUE)

Several hues

Using an image with several prominent hues, a divergent palette is not sensible here. A sequential is likely best sorted by hue.

Note in the second image below, you can also set quantize = TRUE to show a color-quantized reference thumbnail image based on the derived palette. This makes use of the image_quantmap function. Rather than only quantizing the image, it does so while also mapping the colors of any image to an arbitrary color palette based on nearest distances in RGB space.

image_pal(x[3], type = "qual", brightness = c(0.4, 1), plot = TRUE)

image_pal(x[3], type = "seq", bw = c(0.2, 1), saturation = c(0.2, 1), 
          plot = TRUE, quantize = TRUE)

Palette generation uses k-means clustering; results are different each time you call image_pal. If the palette you obtain does not feel right, even with fixed arguments you can run it again to obtain a different palette. Depending on the settings and the nature of the source image, it may change quite a bit. If you need a reproducible palette, set the seed argument. In the example above, the seed was set globally to avoid having to set it in each call to image_pal.

Quantize and remap image colors

You can quantize the colors in an image using image_quantmap directly. Choose any vector of colors. Each pixel has its color mapped to whichever of these colors it is closest to in RGB space. The RGB array is returned. You can plot the image with the palette.

x <- system.file("blue-yellow.jpg", package = "imgpalr")
pal <- c("black", "navyblue", "dodgerblue", "yellow")
a <- image_quantmap(x, pal, k = 7, plot = TRUE)

str(a)
#>  num [1:317, 1:400, 1:3] 0 0 0 0 0 0 0 0 0 0 ...

This works well if you want to quantize the colors to colors a short distance away in RGB space, but if you want to also swap them out for very different colors, this should be a two step process. If you provide an equal-length vector of colors to the pal2 argument, these colors will replace those in pal after the initial quantization.

pal2 <- c("darkred", "darkgreen", "tomato", "orange")
a <- image_quantmap(x, pal, pal2, k = 7, plot = TRUE, show_pal = FALSE)

Note: This function can be very slow for large k and/or larger images.

Related resources

There is also the RImagePalette package on CRAN, which uses the median cut algorithm for finding they dominant colors in an image.

imgpalr was originally inspired by the paletter package on GitHub. Both packages use k-means clustering to find key image colors, but take some different approaches in methods for assembling color palettes.

The palette preview (without the thumbnail addition) is based off of scales::show_col, which is a convenient function for plotting palettes. You can also use pals::pal.bands to do the same using a different visual layout.

If you want to directly manipulate the color properties of an image for its own sake rather than derive color palettes for other purposes, you can do so using the magick package, which provides bindings to the ImageMagick library.


Please note that the imgpalr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].