I recently (well, semi-recently) saw a piece of Travelling Sales Person (TSP) art (featuring a famous Doctor), which I thought was pretty cool. There is a nice suit of open source software that can create this for you, created by the strange geniuses behind Evil Mad Science. I thought, however, that the lines looked a bit jagged, and remembered a computer exercise we coded back in the days when I was attending a course in Artificial Neural Networks (ANN). The task was to create a Kohonen network, a kind of space exploring curve or mesh, that was filled a triangular shape. The end result was a space filling line with a nice organic feel to it. To make the curve approximate an image, all you would have to do was to assign the domain to be explored weights depending on the darkness of the pixels that constitutes it, and voilá: Kohonen-art! (This may seem to be removed from neural networks; the connection is that this too is a kind of learning network, and if appropriately setup it can order or group data.)
Then I forgot about it for a while, until a former co-worker mentioned that his company might be getting a laser etcher. One of the cool things about TSP-art is that, since it is a single line, it is much quicker to draw or etch, than the dot-matrix or stippling approach. So I thought, I could do this, and I set about the task.
The benefit of using a Kohonen algorithm is that you get very nice smooth lines (provided you have chosen your algorithm’s parameters suitably), but the great fall back compared to TSP is that it is very slow to converge. There are excellent TSP solvers, but Kohonen’s algorithm is rather a different beast. Creating the images took several hours, but the resulting piece of code can take any image (though a grey-scale image, preprocessed to have high contrast works best) and create a Kohonen approximation. The results are the images seen in this post.
But that’s not the end of the story.
A co-worker who attended the same course was inspired by this, and spent the next few days writing his own program, that turned out more efficient than mine. This was for a couple of reasons, mainly concerned with him taking the time to think about the problem, rather than just reproducing the old code in Python, which was my approach. Among other things, he made some nice simplifications in the code, regarding cut-offs, decreasing the numerical complexity, but the most interesting features were that he derived a an expression for a more suitable convergence algorithm, and also derived the result that using the square of the darkness value would give a contrast more like that of the original image. The main reason I’m not sharing the code right now is that I never bothered (being a little lazy) making a repository for it. That being said, however, I want to implement these features in my code, and also maybe use Chess board distance (or L_infinity norm) rather than Euclidean distance (or L_2 norm) as a further speed-up (as recommended by Deinonychus).
After that, I will release it under a GPL license.