Calculating the density of characters was rather easy in Borland's IDE. Let im be an image, then:
Now we have the size of a character. The font is monospaced so I can use 'x' or any other character. Now for ch being each character in turn, I clear the image, then print the character on it:
Then in loop where i changes from, say, 0 to width+10 and j from 0 to height+10:
Finally, the density of ink for this character is:
Note that the area that you check inside the (i;j) loop must be greater than the character width*height rectangle because a lot of characters exceed this size. The size is used only to determine the horizontal and vertical distance between characters.
Note also that just counting black pixels in the loop is not a good idea, because some fonts, especially small sized (like 2 or 3) include also some gray pixels which also have to be counted in.
Finally I cut the input image into width*height rectangles and for each of them I calculate the density of ink in a similar way as I did it for characters (only now I have to take into account all colors, and also the color weights) and for each rectangle I use the character that fits best.
This is not the actual code of the program, but I think it is more or less correct and shows the main idea