This is an experiment to try and create an ascii art algorithm. You can see some of the results in the examples folder. Note that only PNG images are supported. The algorithm itself works as follows:
load an image and convert each pixel to the CIELAB color space. This is a perceptual color space that allows for the calculation of a meaningful distance between two colors, as the Euclidean distance between two colors in this space corresponds to uniform changes in perceived color.
reduce the palette of the image to a smaller number of colors. All examples were created by reducing images to 16 colors. This reduction is done by running the k-means clustering algorithm over all image pixels after these have been converted to the CIELAB color space. A parallelized k-means clustering library was used for this. Note that this step is very slow and could be replaced with a faster histogram based approach.
use the contents of the ascii_data folder to associate each of the resulting reduced palette colors with an ascii character. Afterwards the reduced palette image is divided into blocks of 8 x 16 pixels and each block is replaced by the ascii character associated with the block's dominant color.
Creating your own ascii images
AsciiPNG requires several Ruby gems to be installed. You can install all of these in one go by running:
gem install AsciiPNG
You'll need to clone the repository as well as the ascii_data folder is required for AsciiPNG to work. You can do this by running:
git clone firstname.lastname@example.org:vaneyckt/AsciiPNG.git
The contents of the AsciiPNG.rb file should hopefully be enough to get you started :).