From the zero-learning Python series teaches you how to generate character drawings from a picture _python

Source: Internet
Author: User

Next thought:

The original-> grayscale-> is mapped to the specified sequence of characters based on pixel brightness--> output.
The more characters, the more dense the characters change. Effect will be better.
If you make a character picture based on the pixel brightness range of a grayscale image, the effect is better.
If you use the palette again, the character is changed to color, more like the original.

This is the original image:

This is the generated character drawing:

Nonsense not much to say, directly on the code:

Copy Code code 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 Xra Nge to J in Xrange (MB)], (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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.