One fun application of tree-based methods is abstracting over art and other images. For some really striking examples, take a look at designer Dimitris Ladopoulos’ portfolio. This vignette will show you how to implement the same basic ideas using parttree and a few friends. Here are the packages that we’ll be using.
library(parttree) # This package
library(rpart) # For decision trees
library(magick) # For reading and manipulating images
library(imager) # Another image library, with some additional features
op = par(mar = c(0,0,0,0)) # Remove plot margins
While the exact details will vary depending on the image at hand, the essential recipe for this type of art abstraction is as follows:
Our first example, will mimic one of Dimitri Ladopoulos’s aforementioned portrait pieces. Specifically, we will abstract over a close-up (eyes only) of Rembrandt Peale’s portrait of his daughter, Rosalba.
We can download a digital image of the original artwork from Wikimedia. I’ll download a high-res version to show off, but feel free to go for a lower resolution if you want to reduce modeling and plotting times.1 However, I will crop the image around Rosalba’s eyes to get a close-up and reduce the overall complexity of the exercise.2
# Download the image
rosalba = image_read("https://upload.wikimedia.org/wikipedia/commons/a/aa/Rembrandt_Peale_-_Portrait_of_Rosalba_Peale_-_Google_Art_Project.jpg")
# Crop around the eyes
rosalba = image_crop(rosalba, "850x400+890+1350")
# rosalba = image_crop(rosalba, "750x350+890+1350")
# Convert to cimg (better for in-memory manipulation)
rosalba = magick2cimg(rosalba)
# Display
rosalba
#> Image. Width: 850 pix Height: 400 pix Depth: 1 Colour channels: 3
plot(rosalba, axes = FALSE)