We all know that Spain is going to win this world cup 😉, but watching the games is still entertaining. I thought today while watching England vs. Tunisia that soccer players look very much alike, especially within a team, and so I thought I could compute the average face by soccer team for this world cup.
Getting the data, in this case, images for each player in the current soccer world cup is arguably critical. The images need to have a plain background, similar ilumation, and ideally, equal size. Luckly, the FIFA has done all of this, and the images are available online: https://www.fifa.com/worldcup/players/
If you inspect one of the player’s elemtents, you can access the URL for the player’s image, which can then be downloaded programmatically
I downloaded the page’s source code, and downloaded the 736 300 pixels squared images.
Averaging a face
There is a naive way of averaging an image, using numpy, and it only takes a few lines:
import numpy as np import imageio countries = ['argentina', 'belgium', 'colombia', 'croatia', ...] for country in countries: images_stacked = np.zeros((23, 300, 300, 3)) for i in range(0, 23): images_stacked[i] = imageio.imread('images-input/%s/%s_%s.jpg' % (country, country, i)) results = np.zeros((300, 300, 3)) for color in range(0, images_stacked.shape): for x_pos in range(0, images_stacked.shape): for y_pos in range(0, images_stacked.shape): results[x_pos, y_pos, color] = np.mean(images_stacked[:, x_pos, y_pos, color]) imageio.imwrite('images-output/%s_naive_averager.png' % country, results)
There is room for improving on this code, but I am not interested in that, rather on the actual results. And here is how they show:
Let’s look at another example:
Even though images are standard, averaging the pixel values doesn’t build a compeling image; sure, we can distinguish some features such as color of the t-shirt or hair, but we can’t put a face to it.
Luckily, there are better ways. Meet Face Morpher (FM from now own). FM works in a different way to find the average face, instead of naively averaging the pixel values, it builds a geometry of the face by identifying elements on it such as the eyes. It then proceeds to average those sections across images.
The results are much more compeling, and we are definitely able to put a face to this teams now.
Or in the case of Brazil:
I decided to them combine the two images: naive + FM for a more compeling result. I blended the images using Sketch, used the naive image as background, and overlayed a semi-transparent FM face.
Quite happy with the result:
How does the average face look across all countries then?