Wednesday, April 7, 2010

Image to ascii art in Python

After seeing the image-to-ascii post at bestinclass.dk I wanted to try something similar. Well, there are no lisp macros here, but still I'm delighted with the result. The code here is under the BSD Licence.

The algorithm is as follows:

1. Scale an image to some width
2. Convert the image to greyscale
3. Traverse the image pixel by pixel and choose from a list of predefined values the value corresponding to the greyscale of every pixel.

I have used the icy-ubuntu image from:
[http://gnome-look.org/content/preview.php?preview=1&id=73000&file1=73000-1.jpg&file2=73000-2.jpg&file3=73000-3.jpg&name=Icy+Linux] for my tests:


Converted to ascii art it looked like:


I have also tried them with the image of S. Balmer from the abovementioned website (bestinclass.dk), printing at 40 characters per line, and the results were as follows:


And the code:

No comments:

Categories

code (15) fun (2) linux (31) miscellaneous (9) music (8)

About me

I'm Adrian and this is my blog. Here I usually write about technical stuff (mostly about Linux).
Copyright: BY-NC_SA, Author: aeter