There are a lot of character paintings on the Internet, which look cool. here we will show you how to use Python to do such cool things. let's talk about the following ideas:
SOURCE image-> grayscale-> map to the specified character sequence based on the pixel brightness-> output.
The more characters, the more character changes. Better results.
If you create a character painting based on the pixel brightness range of the grayscale image, the effect will be better.
If you use the color palette to color the character, it will be more like the source image.
This is the source image:
This is the generated character painting:
If you don't talk much about it, go directly to the code:
The code is as follows:
Import Image
Chars = "... ',;: clodxkLO0DGEKNWMM"
Fn = r 'C: \ users \ liabc \ desktop \ jianbing.png'
F1 = lambda F: ''. join ([(k % 100! = 0) and m or m + '\ n' for k, m in enumerate (apply (lambda x: [chars [x [j, I] % len (chars)] for I in xrange (70) for j in xrange (100)], (Image. open (F ). resize (100,70 )). convert ("L "). load (),), 1)])
F = open (r "c: \ users \ liabc \ desktop \ aface.txt", "w ")
F. write (f1 (fn ))
F. close ()