This is my 17th day of the August Genwen Challenge

preface

Compression and enhancement of handwritten notes in Python. Let’s get started

The development tools

Python version: 3.5.4

Related modules:

The Scipy module, the NUMpy module, the PIL module, and some Python modules come with Python.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

The main idea

Step1: determine the background color

Assume that the paper color is the one that appears most frequently in the scanned image. It also reduced 8 bits per channel to 6 bits per channel to increase the reliability of background color acquisition.

Step2: Separate the foreground scenery

Color is mapped from RGB space to HSV space to achieve the function of separating foreground scenery.

The default rule is:

(1) Brightness V is more than 0.3 larger than the background color; (2) Saturation S is more than 0.2 larger than the background color.

Meet one of them is the foreground scenery.

Step3: Select the rendering color

It is equivalent to solving a color quantization problem with cluster analysis.

Convert the original 24 bits per pixel image into an image with a small number of representative colors.

Mainly use k-means algorithm to achieve.

Other notes:

(1) By default, the program will increase the brightness and contrast of the final color palette by resetting the maximum and minimum intensity values of colors from 0 to 255;

(2) By default, the program automatically sorts according to the input file name, and the key word is number.

Basic function: py-3.5 note_processor. py + Name of the note image to be processed For example: picture

The results show

Note 1:

Results:

Note 2:

Results:

That’s the end of this article, thanks for watching,Python image effects, next share Python to implement pencil sketch automatic generation.

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

④Python basic introduction, crawler, Web development, big data analysis video (suitable for small white learning)

⑤ A Roadmap for Learning Python

All done~ See personal homepage introduction to obtain the complete source code.