Introduction

Color Theory in Film

Have you ever thought about how colors influence your perception on the movie? How their brightness tone in the emotions on screen? How their hue set up a mood? What the director’s choice of the color palette tells about their intention; what kind of story they want to tell us?

Color is one of the most important parts of storytelling in film industry. Correctly used, it can guide the viewer through the emotional journey along with the plot. Human brain naturally associates colors with different emotions (eg. red with anger, white with calmness, green with peace). Colors influence our perception, create an impression and - in context of movies - can set the tone for the whole screening. Great directors know that, and choose palettes for their movies very carefully.

Aim of this project

For my project I decided to use image clustering method to analyze the dominant colors in four Damien Chazelle’s movies. The aim is to assess, whether the color palette choice matches what emotions are conveyed in the story.

Images processing

For this project I chose film frames from four most popular Damien Chazelle’s movies: “La La Land”, “Babylon”, “Whiplash” and “First Man”. My goal was to choose the most representative pictures, that capture the mood of the movie - usually those were poster images as well.

# libraries
#install.packages("tidyverse")
#install.packages("jpeg")
#install.packages("rasterImage")
#install.packages("plotrix")
library(jpeg)
library(rasterImage)
## Ładowanie wymaganego pakietu: plotrix

After installing rights packages, I can upload necessary images. Second, I inspect their dimensions.

lalaland<-readJPEG("lalaland.jpg")
babylon<-readJPEG("babylon.jpg")
whiplash<-readJPEG("whiplash.jpg")
first_man<-readJPEG("first_man.jpg")

dm1<-dim(lalaland)
dm2<-dim(babylon)
dm3<-dim(whiplash)
dm4<-dim(first_man)

dm1[1:2]
## [1] 438 625
dm2[1:2]
## [1] 600 900
dm3[1:2]
## [1]  675 1200
dm4[1:2]
## [1] 600 900

To process an image, we have to convert it into a numerical matrix. The RGB format is the most suitable for this purpose. This format is convenient because we can interpret the image as a matrix with three columns, representing (in scale from 0 to 255) the amounts of red, green and blue color.

rgbLalaland<-data.frame(x=rep(1:dm1[2], each=dm1[1]),  y=rep(dm1[1]:1, dm1[2]), r.value=as.vector(lalaland[,,1]), g.value=as.vector(lalaland[,,2]), b.value=as.vector(lalaland[,,3]))

rgbBabylon<-data.frame(x=rep(1:dm2[2], each=dm2[1]),  y=rep(dm2[1]:1, dm2[2]), r.value=as.vector(babylon[,,1]), g.value=as.vector(babylon[,,2]), b.value=as.vector(babylon[,,3]))

rgbWhiplash<-data.frame(x=rep(1:dm3[2], each=dm3[1]),  y=rep(dm3[1]:1, dm3[2]), r.value=as.vector(whiplash[,,1]), g.value=as.vector(whiplash[,,2]), b.value=as.vector(whiplash[,,3]))

rgbFirst_man<-data.frame(x=rep(1:dm4[2], each=dm4[1]),  y=rep(dm4[1]:1, dm4[2]), r.value=as.vector(first_man[,,1]),  g.value=as.vector(first_man[,,2]), b.value=as.vector(first_man[,,3]))
plot(y~x, data=rgbLalaland, main="La La Land", col=rgb(rgbLalaland[c("r.value", "g.value", "b.value")]), asp=1, pch=".")

plot(y~x, data=rgbBabylon, main="Babylon", col=rgb(rgbBabylon[c("r.value", "g.value", "b.value")]), asp=1, pch=".")

plot(y~x, data=rgbWhiplash, main="Whiplash", col=rgb(rgbWhiplash[c("r.value", "g.value", "b.value")]), asp=1, pch=".")

plot(y~x, data=rgbFirst_man, main="First Man", col=rgb(rgbFirst_man[c("r.value", "g.value", "b.value")]), asp=1, pch=".")

Clustering

I’m going to apply CLARA Algorithm for Image Clustering. As a first step, I determine the optimal number of clusters using the Silhouette analysis. In a codes below, to every image I apply the clara() function to perform clustering on pixels within picture’s RGB dataframe. Using “loop”, for different numbers of clusters I check the average silhouette width. As the silhouette ranges from -1 to 1 (-1 meaning value was assigned to the wrong cluser; 1 - value is “close” to its cluster) - I can determine the optimal number of clusters by the indetifying the highest point on a graph below

library(cluster)
n1<-c() 
for (i in 1:10) {
  cl<-clara(rgbLalaland[, c("r.value", "g.value", "b.value")], i)
  n1[i]<-cl$silinfo$avg.width
}

plot(n1, type='l', main="Optimal number of clusters", xlab="Number of clusters", ylab="Average silhouette", col="blue")
points(n1, pch=21, bg="navyblue")
abline(h=(1:30)*5/100, lty=3, col="grey50")

n2<-c() 
for (i in 1:10) {
  cl<-clara(rgbBabylon[, c("r.value", "g.value", "b.value")], i)
  n2[i]<-cl$silinfo$avg.width
}

plot(n2, type='l', main="Optimal number of clusters", xlab="Number of clusters", ylab="Average silhouette", col="blue")
points(n2, pch=21, bg="navyblue")
abline(h=(1:30)*5/100, lty=3, col="grey50")

n3<-c() 
for (i in 1:10) {
  cl<-clara(rgbWhiplash[, c("r.value", "g.value", "b.value")], i)
  n3[i]<-cl$silinfo$avg.width
}

plot(n3, type='l', main="Optimal number of clusters", xlab="Number of clusters", ylab="Average silhouette", col="blue")
points(n3, pch=21, bg="navyblue")
abline(h=(1:30)*5/100, lty=3, col="grey50")

n4<-c() 
for (i in 1:10) {
  cl<-clara(rgbFirst_man[, c("r.value", "g.value", "b.value")], i)
  n4[i]<-cl$silinfo$avg.width
}

plot(n4, type='l', main="Optimal number of clusters", xlab="Number of clusters", ylab="Average silhouette", col="blue")
points(n4, pch=21, bg="navyblue")
abline(h=(1:30)*5/100, lty=3, col="grey50")

For “La La Land”, “Whiplash” and “First Man” - 2 turned out to be the optimal number of the clusters. As there are 3 basic colors, the average silouette is posivite, and to make the analysis deeper, I decide to apply k = 3 for those cases. For “Babylon” the optimal number of clusters is 4.

Based on that analysis I’ll apply CLARA algorithm for appropriate number of clusters

clara1<-clara(rgbLalaland[,3:5], 3) 
plot(silhouette(clara1))

clara2<-clara(rgbBabylon[,3:5], 4) 
plot(silhouette(clara2))

clara3<-clara(rgbWhiplash[,3:5], 3) 
plot(silhouette(clara3))

clara4<-clara(rgbFirst_man[,3:5], 3) 
plot(silhouette(clara4))

The clustered images, with colors based on RGB values look as follows:

colors1<-rgb(clara1$medoids[clara1$clustering, ])
plot(rgbLalaland$y~rgbLalaland$x, col=colors1, pch=".", cex=2, asp=1, main="La La Land")

colors2<-rgb(clara2$medoids[clara2$clustering, ])
plot(rgbBabylon$y~rgbBabylon$x, col=colors2, pch=".", cex=2, asp=1, main="Babylon")

colors3<-rgb(clara3$medoids[clara3$clustering, ])
plot(rgbWhiplash$y~rgbWhiplash$x, col=colors3, pch=".", cex=2, asp=1, main="Whiplash")

colors4<-rgb(clara4$medoids[clara4$clustering, ])
plot(rgbFirst_man$y~rgbFirst_man$x, col=colors4, pch=".", cex=2, asp=1, main="First Man")

Colors Interpretation

Thanks to the clustering method applied above, I received a list of the most prominent colors from each of the film frames. Now, I’ll analyze the outputs in context of Color Theory in Film.

dominantColors1 <- as.data.frame(table(colors1))
dominantColors1$colors1 <- as.character(dominantColors1$colors1)
pie(dominantColors1$Freq,
        col = dominantColors1$colors1, main = "Colors in La La Land", labels = NA)

dominantColors1
##   colors1   Freq
## 1 #12163B 123568
## 2 #3E17A6 129120
## 3 #8F5B34  21062

The dominant colors in “La La Land” film frame are navy, purple and yellow. In relation to Color Theory in Film and in Art, they may represent following emotions: yellow may refer to happiness, optimism and imagination - that would strongly resonate with personalities of the two main characters of the movie, that can be described as the infantile dreamers, looking for opportunities to become “someone” in artistic world of Hollywood. Navy/dark blue is the color of reliability and strength - it is also a complimentary color to yellow, which makes the second one pop-up on a screen and creates the sense of drama on the screen. The romance - which purple color can represent - is an important part of the movie’s plot as well.

dominantColors2 <- as.data.frame(table(colors2))
dominantColors2$colors2 <- as.character(dominantColors2$colors2)
pie(dominantColors2$Freq,
        col = dominantColors2$colors2, main = "Colors in Babylon", labels = NA)

dominantColors2
##   colors2   Freq
## 1 #1C0905 130565
## 2 #4B1D06 214804
## 3 #783D15 135212
## 4 #BC6935  59419

The dominant colors in “Babylon” we can classify as: scarlet - red, orange, gold and black. Lots of black color in the background captures the mystery and the rebellion mood, as many of the movie characters have a thing or two on theirs’ conscience. The red color represents the passion and romance which are play an important role in movie’s plot. It is also usually associate with blood and violence - which “Babylon” doesn’t miss either. But the movie also fall into the category of the comedy, and the warm orange tones on the screen correspond to that, bringing cosiness and positive emotions. Finally the golden tones refer to the richness and wealth that were a part of the early hollywood stars’ lifestyle.

dominantColors3 <- as.data.frame(table(colors3))
dominantColors3$colors3 <- as.character(dominantColors3$colors3)
pie(dominantColors3$Freq,
        col = dominantColors3$colors3, main = "Colors in Whiplash", labels = NA)

dominantColors3
##   colors3   Freq
## 1 #0B060C 404033
## 2 #261B17 295815
## 3 #746A61 110152

In “Whiplash” colors that dominate are: black, brown and grey. Black and grey tones capture the depressing, heavy mood of both the protagonist as well as the overall plot. Black color may be also associated with the power that teacher has over his student (both being the main characters). Dark brown shades in color theory are associated with steadfastness - another primary trait of the protagonist. It can be said, that in this movie, director’s choice was mainly the attempt to reflect the inner life of the main characters through the colors.

dominantColors4 <- as.data.frame(table(colors4))
dominantColors4$colors4 <- as.character(dominantColors4$colors4)
pie(dominantColors4$Freq,
        col = dominantColors4$colors4, main = "Colors in First Man", labels = NA)

dominantColors4
##   colors4   Freq
## 1 #232321 169271
## 2 #8A6548 159068
## 3 #A9C0C6 211661

The dominating color in “First Man” are: black, brown and blue. The black color surely refers to the mystery of the main character and his story - story of the first ever man that landed on the Moon. Blue and brown colors may represent two “worlds” in which the plot is set: the sky and the earth.