-1

I need to make a program in C using SDL2 that converts images to ASCII art. I uploaded the image in the program, raised the contrast a bit and turned it into grayscale.

What should I do now? Should I create an array with a few ASCII characters (.+xo0%@#) ranging in "Intensity" then replace the pixels with the characters of similar intensity?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Sounds good to me, just do it? – HolyBlackCat Jan 16 '18 at 19:34
  • 2
    Your proposal sounds quite adequate. Asking how to do it is however too broad. In my opinion (probably not objective, do not worry) ASCII art implies more finesse than replacing pixels by ASCII with different "gray values". But do implement a program which acts as described. If you get stuck with a specific problem describe that and you will most likely find people happily helping you. Oh, and welcome to StackOverflow! Take the [tour] at your leisure. – Yunnosch Jan 16 '18 at 19:34
  • Thank you very much for the help and for the warm welcome . I will do my best! – Rosca Radu Jan 16 '18 at 19:39
  • There have been some questions like this: https://stackoverflow.com/questions/394882/how-do-ascii-art-image-conversion-algorithms-work. Basically, you have to group greyed pixels into blocks and each block should be replaced by the symbol. Mapping of blocks to symbol is more complicated. – VladP Jan 16 '18 at 22:41
  • If there are no restrictions from your instructor regarding ASCII character mapping, I would just try it with several different maps and see which one looked the best. – Mark Benningfield Jan 17 '18 at 00:42
  • I have changed all the pixels in the picture with a character of approximate intensity and added them in a 2D Char array . Now im trying to find a way of outputting the values on a text file or render them down on a image. Plus I'll try to raise the area that im calculating the intensity on the image to the size of the mono spaced font I'm using so i don't have to print out thousands of symbols but (widthofimage/widthoffont)*(heightofimage/heightoffont) which is smaller and keeps the proportions of the image. Problem is I have no clue on how to do that. – Rosca Radu Jan 17 '18 at 02:39

1 Answers1

0

You need to dissect your image into areas that have the same horizontal and vertical proportions as a fixed-width character. Let's call this dimension a "cell".

You will also need a map of each character, but rendered as an image into the same "cell".

Then you will need to do a fuzzy match of the cell of the image to the character cells. The one that matches most closely is selected for the output. There are multiple ways of matching things, and this gets related to AI visual research.

The most powerful techniques detect edges, and reduce the complexity of the image to permit a better line representation of the image before attempting a character match. This is because the best ascii art is more aligned to line art, rather than photo type art.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138