Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python3 code to add beauty effect to pictures

Shulou Source: shulou.com Published: 2022-05-31 20:24:55 10月03日 Update

This article mainly explains "how to use Python3 code to add beauty effect to pictures", the content in the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use Python3 code to add beauty effect to pictures" bar!

1 module installation

Because it is a third-party module, the old rule, the first step, install:

Pip install pillow

For other installation methods, please read these two articles directly:

Python3 automatically installs third-party libraries to say goodbye to pip

Python: one line of code to import all Python libraries

Here is a simple sentence:

The class of ImageEnhance in the PIL module is specially used for image enhancement processing

It can not only enhance (or weaken) the brightness, contrast and chromaticity of the image, but also can be used to enhance the sharpness of the image.

After the installation, you also understand the class methods, and then you will practice the code.

2 read the image

Code example:

#-*-coding:utf-8-*-# @ Time: 2022-04-pictures @ Author: carl_DJfrom PIL import Image,ImageEnhance "read pictures" image = Image.open ('. / data/mm.jpg') image.show ()

Running result

The open picture is the original picture.

3 enhance brightness

Code example:

#-*-coding:utf-8-*-# @ Time: 2022-04-reading @ Author: carl_DJfrom PIL import Image,ImageEnhance "read picture" image = Image.open ('. / data/mm.jpg') # image.show () "enhance brightness" bright_enh = ImageEnhance.Brightness (image) # adjust luminance value brightness = 3image_brightened = bright_enh.enhance (brightness) image_brightened.show ()

Running result:

4 enhanced chromaticity

Code example:

#-*-coding:utf-8-*-# @ Time: 2022-04-read @ Author: carl_DJfrom PIL import Image,ImageEnhance "read picture" image = Image.open ('. / data/mm.jpg') # image.show () "enhanced chromaticity" color_enh = ImageEnhance.Color (image) # adjust chromaticity color = 3image_colored = color_enh.enhance (color) image_colored.show ()

Running result:

5 enhance the contrast

Code example:

#-*-coding:utf-8-*-# @ Time: 2022-04-pictures @ Author: carl_DJfrom PIL import Image,ImageEnhance "read picture" image = Image.open ('. / data/mm.jpg') # image.show () "enhance contrast" contrast_enh = ImageEnhance.Contrast (image) # adjust contrast contrast = 3image_contrasted = contrast_enh.enhance (contrast) image_contrasted.show ()

Running result:

6 sharpening

Code example:

#-*-coding:utf-8-*-# @ Time: 2022-04-pictures @ Author: carl_DJfrom PIL import Image,ImageEnhance "read picture" image = Image.open ('. / data/mm.jpg') # image.show () "enhance contrast" contrast_enh = ImageEnhance.Contrast (image) # adjust contrast contrast = 3image_contrasted = contrast_enh.enhance (contrast) image_contrasted.show ()

Running result:

Thank you for your reading, the above is the content of "how to use Python3 code to add beauty effect to pictures". After the study of this article, I believe you have a deeper understanding of how to use Python3 code to add beauty effect to pictures. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Code picture contrast example result utf-8 run effect beauty brightness image chromaticity adjustment module learning content that is third party next one line Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple NVidia OPPO Reno Xiaomi