HIDIHO!

giving something back to the Flash community

ASCII drawing

Tags: , ,

(somewhat clever) ascii art tool
a quickie for the sake of coding.

I’ve doen a small ASCII drawing script after seeing this artist in action. via http://text-mode.tumblr.com/

check her website for more: http://www.geocities.com/spunk1111/ ( art direction is moving, the pre-RSS “rings” at the bottom :’) ).

what interested me in her doodles is the subtle and rather elegant way some characters were used. being subtle is something computers are usually bad at so I started thinking of a better way to draw ASCII art.

the ussual unsubtle way is to create a table by getting the grey value of a set of letters.
then scan a picture pixel by pixel, get the pixel’s luminance, match it with the closest value of the characters’ table and draw the letter instead of the pixel eventually using the pixel’s color.

the result is way less expressive than a handmade ASCII art, mostly because it creates an optical grey and doesn’t take into account the features of the picture. 5 years ago, I did something in the way( without the association table if I remember well), you can check a live version here and some results there.

I thought a good start would be to quantify each letters in a more clever way than just getting its average grey value. so I took the ( very handy ) colorsBoundRect of each glyph which gave me this spritesheet where each character is associated with a bounding rectangle (brown yellow shape around glyph):
letters spritesheet
when drawing on the grid, I split the canvas into little boxes and check if the box contains something.
if it’s not empty, I extract the colorsBoundRect and try to find the best match amongst the above rectangles.

first I thought it would be easy to find 2 rectangles that “look” the same but it’s not.
I started comparing the areas ( width / height ), the positions, the intersections between the 2, or giving a better score to rectangles that contained or were contained by my source rectangle… nothing worked.

then I used the Moment of the binary image as described and implemented here: http://www.mukimuki.fr/flashblog/2009/05/20/magic-moments/ thinking that having a global angle of the shape would make it more efficient.
but it didn’t work either…

so I browsed and found some very interesting papers about shape recognition:

anyway typing “shape recognition algorithms” in Google is like opening a candy box.

and at some point they explain that, like for so many things, swapping to a Fourier domain was the way to go but COME ON! I mean those are just rectangles… there has to be a simpler way. so I used a variant of the non overlapping circular distribution * and well… it was good enough for me.

rectangle match – wonderfl build flash online

the green rect is our target, the red one is the solution, whitish are approaching attempts.
it was forked and improved by Makc btw.

as my rectangles were detected somewhat properly, I built a small test.

ASCII drawing – wonderfl build flash online

that was (only) it,
enjoy :)

Tags: , ,

© 2009 HIDIHO!. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.