SoFunction
Updated on 2024-11-19

Introduction to the use of the ImageEnhance module of the Python image processing library PIL

The ImageEnhance module provides a number of classes for image enhancement.

I. Interface of ImageEnhance module

All enhancement classes implement a common interface, including a method:

(factor) ⇒ image

This method returns an enhanced image. The variable factor is a floating point number that controls how much the image is enhanced. A variable factor of 1 will return a copy of the original image; the smaller the factor value, the less color (brightness, contrast, etc.) and the more value. There are no restrictions on the variable facotr.

II. Color class of ImageEnhance module

The Color Enhancement class is used to adjust the color balance of an image, in a way similar to controlling a color television set. The enhancement interfaces implemented by this class are as follows:

(image) ⇒ Color enhancer instance

Creates an enhancement object to adjust the color of the image. An enhancement factor of 0.0 will produce a black and white image; 1.0 will give the original image.

instance of the class:

>>> from PIL import Image, ImageEnhance

>>> im02 =("D:\\Code\\Python\\test\\img\\")

>>> im_1 = (im02).enhance(0.1)

>>> im_5 = (im02).enhance(0.5)

>>> im_8 =(im02).enhance(0.8)

>>> im_20 = (im02).enhance(2.0)

From the previous introduction, we can learn that the parameter factor of the function enhance() determines the color saturation situation of the image. From 0.1 to 0.5, to 0.8, 2.0, the color saturation of the image increases in turn.

The image im_1 is as follows:

                             

The image im_5 is as follows:

The image im_8 is as follows:

Image im_20 is below:

Third, the ImageEnhance module's Brightness class

The Brightness Enhancement class is used to adjust the brightness of an image.

(image)⇒ Brightnessenhancer instance

Creates an enhancement object that adjusts the brightness of the image. An enhancement factor of 0.0 will produce a black image; 1.0 will keep the original image.

instance of the class:

>>> from PIL import Image, ImageEnhance

>>> im02 =("D:\\Code\\Python\\test\\img\\")

>>> im_2 = (im02).enhance(0.2)

>>> im_5 = (im02).enhance(0.5)

>>> im_8 = (im02).enhance(0.8)

>>> im_20 = (im02).enhance(2.0)

The parameter factor of this function, enhance(), determines the brightness profile of the image. The brightness of the image increases in order from 0.1 to 0.5 to 0.8 and 2.0.

The image im_2 is as follows:

The image im_5 is as follows:

The image im_8 is as follows:

Image im_20 is below:

IV. Contrast class of the ImageEnhance module

The Contrast Enhancement category is used to adjust the contrast of an image. Similar to adjusting the contrast of a color television set.

(image)⇒ Contrast enhancer instance

Creates an enhancement object that adjusts the contrast of the image. An enhancement factor of 0.0 will produce a pure gray image; 1.0 will keep the original image.

instance of the class:

>>> from PIL import Image, ImageEnhance

>>> im02 =("D:\\Code\\Python\\test\\img\\")

>>> im_1 = (im02).enhance(0.1)

>>> im_5 = (im02).enhance(0.5)

>>> im_8 = (im02).enhance(0.8)

>>> im_20 = (im02).enhance(2.0)

The parameter factor of this function enhance() determines the contrast profile of the image. The contrast of the image increases in order from 0.1 to 0.5 to 0.8 and 2.0.

The image im_1 is as follows:

The image im_5 is as follows:

The image im_8 is as follows:

Image im_20 is below:

V. Sharpness class of the ImageEnhance module

The Sharpness Enhancement class is used to adjust the sharpness of an image.

(image)⇒ Sharpness enhancer instance

Creates an enhancement object that adjusts the sharpness of the image. An enhancement factor of 0.0 will produce a blurred image; 1.0 will keep the original image, and 2.0 will produce a sharpened image.

instance of the class:

>>> from PIL import Image, ImageEnhance

>>> im02 =("D:\\Code\\Python\\test\\img\\")

>>> im_0 = (im02).enhance(0.0)

>>> im_20 = (im02).enhance(2.0)

>>> im_30 = (im02).enhance(3.0)

The parameter factor of this function enhance() determines the sharpness profile of the image. The sharpness of the image increases sequentially from 0.0 to 2.0 and then to 3.0.

The image im_0 is as follows:

Image im_20 is below:

Image im_30 is below:

VI. ImageEnhance Example

#-*- coding: UTF-8 -*-  
 
from PIL import Image
from PIL import ImageEnhance
 
# Raw images
image = ('')
()
 
#Brightness enhancement
enh_bri = (image)
brightness = 1.5
image_brightened = enh_bri.enhance(brightness)
image_brightened.show()
 
# Chromaticity enhancement
enh_col = (image)
color = 1.5
image_colored = enh_col.enhance(color)
image_colored.show()
 
#Contrast Enhancement
enh_con = (image)
contrast = 1.5
image_contrasted = enh_con.enhance(contrast)
image_contrasted.show()
 
# Sharpness enhancement
enh_sha = (image)
sharpness = 3.0
image_sharped = enh_sha.enhance(sharpness)
image_sharped.show()

to this article on the Python image processing library PIL ImageEnhance module to introduce the use of the article is introduced to this, more related PIL ImageEnhance module content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future!