Select colours from an image in R with {eyedroppeR}

[This article was first published on R Archives - Dan Oehm | Gradient Descending, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

There are fancy ways to extract colours from images but sometimes it’s easier if you could simply click on the image and choose the colours you want.

With eyedroppeR you can click on an image to return the hex codes of the selected pixels all within R.

Installation

Install from GitHub.

devtools::install_github("doehm/eyedroppeR")

For more info follow the link to the GitHub repo.

Usage

Use eyedropper with the following steps:

  1. Find the image you want to pick colours from online.
  2. Right-click and ‘copy image address’.
    • As an example use the image below (right-click > copy image address). 
  3. Choose how many colours to pick e.g. n = 5.
  4. Run pal <- eyedropper(n = 5).
    • eyedropper will read the copied address from the clipboard if img_path is left as NULL
    • If you have a local file or a saved path you can reference it directly with 
      pal <- eyedropper(n = 5, img_path = path)
  5. Click the 5 desired colours. The image will be stretched to the borders of the window, but that’s OK.
  6. Done! Copy the returned string and add it to your script and start using pal.

Other functions

  • sort_pal: allows you to manually sort a palette by clicking on the colours in order. It also allows you to select a specified number of colours if you don’t want them all.
  • extract_pal: automatically selects a specified number of colours using a clustering algorithm. It will read the image path from the clipboard as well and allow you to sort the colours after they are extracted.
  • show_pal : Simple helper to display the palette.

The post Select colours from an image in R with {eyedroppeR} appeared first on Dan Oehm | Gradient Descending.

To leave a comment for the author, please follow the link and comment on their blog: R Archives - Dan Oehm | Gradient Descending.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)