[showcase] image to text converter

I wrote a litte programm that takes an image and generate a new image only containing letters out of it.
Load this image inside the programm and it will be converted into something like this.
You download it from here. I can also upload the source code if you are interessted.


Cool! I always had a soft spot for this kind of thing. Does it work by finding the average pixel value of a character sized region, and then assigning a corresponding character to that region?

It first writes down all the letters it can use and looks how much area they cover. For example a “.” would be very little and “B” very much. Than it goes through evey pixel and set it to a fitting letter. A black pixel would be something like “B” and a very light pixel would be something like “,”.

Ok, I get the character from pixel value part, but it does that for a symbol-sized region of the image at a time, right? (-Like it averages out the values of a cluster of pixels to assign a character based on that average? -or just the most occurring value within a character-sized region?)

It first scales the image so that every pixel in the scaled image will be one letter (5x6pixels) in the new image. Then it looks up every pixel and assigns a letter to it.

Examples (white background):
pixel to assign is black (rgb: 0,0,0) -> (0+0+0)/(255*3)=0
“B” is the letter that will generate the darkest region so the pixel will be converted to “B”

pixel to assign is red (rgb: 255,0,0) -> (255+0+0)(255*3)=0,3333…
a letter which will generate a lighter region than “B”, something like “O”

pixel to assign is white (rbg: 255,255,255) -> (2553)/(2553)=1
so it will search for the letter that generate the lightest region, something like “.” or in my case just " "

In the program you can choose if the background should be black or white and depending on this different letters will be choosen.

Unrelated, just gonna mention that in VLC, under video output settings you can select “ASCII” or “Color ASCII” as an option. It’s very entertaining to watch a video that way :slight_smile:


oh, literally a symbol per pixel, got it! -thanks! Have you tried an averaging or mean approach, so image size can remain the same?

I was thinking about doing my approche with a video, but I am not sure if this would be able to run in realtime and I have never done anything with videos in monogame.

For the image to come out at the same size the program just need to scale it down by a factor of 6 (font height). I already needs to redraw the image at a litte bit stretcht so I can translate every pixel to a letter while keeping the apect ratio (letter height and width is not the same).

Like cra0zy wrote above, real-time is achievable for video. I think I saw a guy do it with skype once, too.

Not what I would call playable, but Quake 2 in real-time text mode.

It eats CPU like crazy…

Ok I rewrote it but this time in a shader. It does the same thing as before but runs much faster. It now works in realtime and so I tested it with a video:
black and white
color 1 and color 2

Well if you can get a video to run in monogame please share.
I tried like crazy for some time, i had so many problems i just finally gave up.

You can download the project here. I hope you can understand what it is doing.

Getting video to work is easy, just write a custom processor / importer to do the work for you in the Pipeline Tool before hand, and then just load the text. Of course, you could also do it in real time, but it’s really a CPU hog.

If you write it as a shader it is not cpu intense. But you would just get the image and not the text of it.

This sounds like a hacky way to do things if you just want video in your game :stuck_out_tongue: