I’ve been experimenting with iteratively generating approximations of images using black lines.
The algorithm works by randomly placing 40 black lines on 40 copies of a blank source image, each of those 40 is then compared to the goal image using SSIM to measure similarity. If any of the 40 are more similar than the source image that image is used as the source for the next iteration of the algorithm. If none of the 40 are more similar then the algorithm repeats with the original source image until a closer similarity is found.
SSIM was chosen as the similarity measure over the traditional PSNR or mean squared error measures because it is a better suited (although not perfect) method for measuring the similarity between two image as perceived by the human eye.
Plotting the change in SSIM over 9000 iterations results in the following fairly predictable graph.
From this graph it can be seen that beyond roughly 3500 iterations little extra structural similarity is obtained.
Comparison with PSNR & MSE
The following two image show the same algorithm but run using means squared error and psnr respectively.
As you’d expected the images are very similar as they are essentially the same metric but scaled differently.
Plotting the mean squared error against iterations produces a similar graph to one for SSIM, but note the inversion of the shape due to mean squared error measuring dissimilarity.
Also notable is how the curve of the graph flattens much quicker (at around 1500) when compared to SSIM.
In an application such as this where the end result is inherently subjective it is difficult to make a strong assertation about the best similarity measure for this purpose. Personally I prefer the results created by SSIM as I feel it captures some of the finer facial features which helps to produce a more recognizable end result.
The code for this project was written in python based mainly on the PIL and pyssim libraries. The following is a version of the code used to generate the above images with a few bits of logging code removed.
The number of iterations is hard coded to 9000 and the number of images in a generation is set at 40. These are fairly arbitrary decisions and can be easily altered in the code for experimentation. Also included in the code are two methods for computing psnr and mean squared error.
Installing Dependencies on Ubuntu
Pyssim can be installed through pip (the python package index). To get pip run:
sudo apt-get install python-pip
To speed things along I recommend installing the following packages before installing pyssim:
sudo apt-get install python-matplotlib python-scipy python-numpy
Finally run the following command to install pyssim via pip:
sudo pip install pyssim