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:
Copy codeThe 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 ()