# Day 47-50: Paletter

Okay! It’s a Thursday evening. Solo parenting is over. My partner is back in town. The kids are in bed. Tina Turner is playing over the wireless. I’m the last one awake. Time for an R post, because that’s just the kind of girl I am. As usual, my inspiration is the wonderful #rstats twitter community, and today’s discovery was prompted by this very fun tweet by Natalie Pilakouta:

I mean, how can I see this and not take it for a spin? It’s so beautiful. The package is available on GitHub here here, and I started out by following the instructions from this post, but as usual I kind of went off script just to see what would happen. I did notice that when it installed it seemed to install packages from source that I swear I already had binaries for on my machine, but eh. That’s not the sort of thing I usually worry about, and I don’t propose to start now while Nutbush City Limits is playing!

## First impressions

To get started, I used the The Four Trees from Monet’s poplar series as the target image (Get it, first “impressions”? I’m so funny)

The first thing I realised is that the full image above is overkill: I don’t actually want to work with the full 1920x1836 pixel image! That takes a while for my poor little laptop to process, and it doesn’t really make much of a difference to the result, so I stripped it back to a 150x143 pixel version and it’s super-fast. The command is pretty straightfoward:

four_trees <- create_palette(
image_path = file.path(root,"img","paletter","the_four_trees_small.jpg"),
number_of_colors = 20,
type_of_variable = "categorical"
)

The four_trees palette that it produces is a vector of 20 hex colours.

four_trees
##  [1] "#DA926E" "#C6A88E" "#CAB09A" "#BA9A7A" "#AFA090" "#CCA878" "#C6AF90"
## [15] "#B6D2DF" "#D3E4F1" "#9DBFE3" "#AFC9E3" "#4C5986" "#7C5F76"

Here’s what the palette looks like, plotted using scales::show_col:

show_col(four_trees)

Taking a closer look at the package, it looks like it does handle continuous scales, but I’m guessing that aspect is a work in progress? At least for the version I installed (0.0.0.9000), there’s a typo internally in the optimize_palette function, so you have to specify "continous" to get the output! 😀

four_trees_continuous <- create_palette(
image_path = file.path(root,"img","paletter","the_four_trees_small.jpg"),
number_of_colors = 20,
type_of_variable = "continous"
)
show_col(four_trees_continuous)

Hm. Well, I don’t know what else I was expecting?

I’ve run it a few times and occasionally it produces results with a broader span of blues for this image but I can imagine it will have some difficulties in general when the raw image has so much of the same colour? Probably my fault for playing with a package at such an early stage of development. The categorical version seems to work very nicely though (under the hood it seems to be doing a k-means clustering of the image pixels, and tweaking the results to be more sensible), so here are a few I have tried.

## I am trying my best

❤️ Me too, little possum. Me too.

## A sunset, because I guess I should?

I suppose I should try a sunset picture, right? I mean, it seems almost obligatory.

Eh. Sunsets are lovely and the palette is nice, but I kind of want to try out something different! Perhaps some camels?

## Paletter with two dromedaries and a donkey

One of (minor) reasons I chose to do my honours thesis with Doug Vickers - besides the fact that he was one of the smartest and loveliest people I ever met - is that he had a print of Paul Klee’s painting With Two Dromedaries and a Donkey hanging in his office, and I’ve always adored that painting.

Here’s the paletter version:

## The Fauves

Looking at the palettes produced so far, I realise that the package does a decent job, but some of the muted or subtle colours in these images aren’t really doing it any favours. The colour balance in a lot of these images is subtle, and for the paintings in particular the composition by the artist is doing a lot of the work that paletter is stripping out (I mean, who’d have thought there’s more to the colour balance of a painting than $$k$$-means clustering reveals??). In retrospect that’s kind of obvious, so my next thought is to give it something more fun to sink its metaphorical teeth into. Let’s give it some fauvism! I mean, an “orgy of colours” is kind of the point, right?

Here’s Luxury, Calm, and Desire by Henri Matisse (1904), and the palette it inspired:

That’s more like it! The shift in palette from Matisse to André Derain’s 1906 work The Dance isn’t exactly subtle, and paletter does a good job on this one too:

Next, I wondered if I could find some more contemporary fauvist images of Sydney. A few minutes on Google uncovered the work of Jos Coufreur, and I am in love. His work is gorgeous. So instead of giving into my Sydneysider’s narcissism, here’s the instagram post showing a painting of the Newcastle Ocean Baths:

A post shared by Jos Coufreur (@joscoufreur) on

Here is the paletter output:

I could play with this for hours. This is absolutely going to get used in putting slides together for next semester’s teaching!