Harshdeep 2.0

April 9, 2006

Creating my own Ascii art

Filed under: Uncategorized — harshdeep @ 10:33 am

I remember seeing an email with pictures of bollywood actresses as ascii text. As a completely unnecessary and useless excercise, I decided to try doing it on my own last night (I tend to do such things after a boring day). Surprisingly, I had a working program to create ascii text image from a jpeg within 15 minutes.

The algorithm, as our Maths prof would put it, is idiotically simple. Some characters are "darker" than others. For example, a hash (#) is darker than a dot (.) – it has more black pixels. So, all you need to do is replace each pixel (or set of pixels) with an ascii character depending on the luminosity of the pixel(s). The characters I used are '@', 'p', '*', 'a', '1', ':', '.' and ' ' (space) in decreasing order of darkness. This is a crude method but it gives pretty decent results. Send me a message if you want the source code.

An example (with due apologies to Ms Katrina Kaif)

Output 1- 100 characters per line, viewing in MS Word – Courier New Font (so that every character takes the same width), Font size 6

Output 2 – 200 characters per line (Higher resolution 🙂 ), Font size 4 (Click to see full-size image)

I used CxImage library for loading jpeg images. I've been using this library since college days for all image manipulation stuff. Sadly, it is not being maintained anymore – it is still available as VS 6 project, I had to make a couple of minor changes to build it on VS 2005.

Advertisements

11 Comments »

  1. Nice….now try doing the reverse:D

    Comment by samreen dhillon — April 9, 2006 @ 12:56 pm

  2. I recommend a different strategy… you should subdivide each ASCII character into the regions corresponding to the pixels each will represent. Then add up the difference in luminosities for each region and the pixel that region represents and find the most appropriate character this way. This should yield sub character resolution.

    Comment by Asteron — April 10, 2006 @ 3:12 am

  3. Good idea, Asteron. I'll try it out sometime. There's another issue in the current approach – the aspect ratio of the output is different because each character is mapped to a pixel and their aspect ratios are different. If a character is mapped to a region of the image, this can also be corrected. But then, this was just supposed to be a quick (and dirty 🙂 ) way of generating ascii art.

    Comment by harshdeep — April 10, 2006 @ 9:34 am

  4. interesting 😀

    Comment by harry — April 10, 2006 @ 7:42 pm

  5. Nice results, but the starting image is pretty contrasty. Does it work with blondes as well with more subtle skin tone variations?

    Comment by blagermeister — April 13, 2006 @ 9:37 pm

  6. Wow, that’s cool.. So if I understand it correctly, you didn’t actually write every single character by hand from scratch, did you? Heh, cause that would have been mad!
    But you’re smart who can make algorithms…

    Comment by Tina — April 13, 2006 @ 11:57 pm

  7. Blagermeister, I haven’t tried using this on blondes (I like brunettes better), but ofcourse, the program works better with high contrast images and it’s far from perfect – there must be a 100 different ways of improving it. But it’s definitely fun sending somebody a Word file and adding the instructions “Select All, Change font to Courier New and font size to 6” and voila, they see their own face 🙂

    No Tina, I’m really not mad enough to write every character myself 🙂

    Comment by harshdeep — April 14, 2006 @ 7:02 am

  8. cool man :)..i am proud of u 🙂
    But for the reverse mechanism , I guess sub pixel approach will give good results

    Comment by ritesh — May 22, 2006 @ 8:39 am

  9. :.dMM@MMMMM@@@@@@@@NNb;
    ;d@@@@@@@@@@@@@@@@@@MM@@MX;
    .ON@@@@@@@@@@@@@@@@@@@@NM@@@Mb:
    ;dN@@@@@@NNM@M@@@@@@@@@@@@@@@@@MNo
    ;N@@@MNXXOOOooOOXN@@@@@@@@@@@@@@@@MN;
    dM@@@Xo:::::.”‘::::oOX@@@@@@@@@@@@@@@Nb
    dN@@@X::.:” ”’.:ooXN@@@@@@@@@@@@@@Mb.
    :N@@@N::.:”” “::OXXM@@@@@@@@@@@@@@Mb
    OM@@Xo:..’ :oOoNM@@@@@@@@@@@@@@Mb
    :NM@@O::.: ‘::oONM@@@@@@@@@@@@@@N;
    dM@@N::::: ::OXN@@@@@@@@@@@@@@@Nb..
    ,O@@@O::.:’ ::ON@@@@@@@@@@@@@@@@@@NXOo;
    O@@@OOOO::. ,;……;.’ ::ON@@@@@@@@@@@@@@@@NN: ”
    :N@@NOo:XNX:.. :oOXXO””:o::::oXM@@@@@@@@@@@@@@@@@b
    ‘O@@oOoOoooo:. ‘:::;;. ‘”o;.::O@@@@@@@@@@@@@@@@@Nb
    :N@XN@OMXOo:. .;”:ONMNXo;.:o;.::XM@@@@@@@@@@@@@@@@N.
    :Y@X@:.NMO:: ;.:.X:”NMOOO:.:::::N@@@@@@@@@@@@@@@@@O
    :O@Oooooo:’ ..;’ ‘::o:oooo:”.:::oN@@@@@@@@@@@@@@@@@N:
    :XX::…:: ,… ”'”‘” ::::oNM@@@@@@@@@@@@@@@@@O.
    No.’ ;:: ;..;. :;:::ONN@@@@@@@@@@@@@@@@@:o;;
    :N:;:’::: :”::; :..::::ON@@@@@@@@@@@@@@@@@@Xo;:;.
    ,dX:.’ ‘:;;;’.;:: ;. :.::::::XNN@@@@@@@@@@@@@@@@@NO;;”o:
    ;NO:. :::::””‘”” :; :.::::::oXNOXOOoN@@@@@@@@@@@@@@Nb;:O
    :OMN:..;::::;:..;” ‘:: ::::::::oNO:::::oO@@@@@@@@@@@@@@@@OX:
    dNM@::.:ooooo;..::. ‘. :.:::::ooOoo;.;:oM@@@@@@@@@@@@@@@@@MO
    ONX::.::XXP”””””:OOO:” :;.:::::ooo::::::N@@@@@@@@@@@@@@@@@@MN;
    :O: “o: ;ooo:o:”::o:”” ”;.:::oo:;:.;oX@@@@@@@@@@@@@@@@@@@@PO
    : o:..::::::””‘ :.:::oOXbd:X@@@@@@@@@@@@@@@@@@@@@@:’.
    ‘ ;’;…’:.:” “.:::oOoONN@@@@@@@@@@@@@@@@@@@@@@o'”‘
    ‘ :::..:”” ..::oOooOXN@@@@@@@@@@@@@@@@@@@@@@o
    ‘:;;;’ ,:;:::oXooooOM@@@@@@@@@@@@@@@@@@@@@@X: :
    “‘:’ .;;;;.:::ooXoooONN@@@@@@@@@@@@@@@@@@@@@@@@Nbb. ;’
    ;'”….;::::::ooOOOOOo:oXM@@@@@@@@@@@@@@@M@@@@@@@@@@@N@@XO;
    :NX; ‘”::oooOOOoooo::::oXXM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Nb
    .:HAC:. ,d:’Y;;.;::oo::::::::..:oON@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@MX
    ,,’;;dbo::::::::::::…;:oN@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O
    ‘”‘””Yo: :::::…:…..::O@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@N:
    : ‘:::……::.:.o@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@MX’
    ,:.'” :::::…:::::;@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@Nb.
    ” ::::::::::::O@@@@@@MN@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NO’
    ‘::::::::::OM@@@@@NM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Mb:
    :::::::::oM@@@@MM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NM@N;
    ‘:::::::oX@@@@@@@@@@@@@@@@@@MM@@@@@@@@@@@@@@@@@@@@oO@NP’
    “”””””””””””””””””””””””””””””””””””””””””””””””””””‘

    Comment by Horroroso — July 14, 2006 @ 4:33 pm

  10. mmm.. could you change to fixed character?

    Comment by Horroroso — July 14, 2006 @ 4:33 pm

  11. Katrina Kaif

    Can u provide more information about this ?

    Trackback by Property Auction — October 2, 2006 @ 12:39 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: