欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python图像处理库ImageEnhance实现图像的亮度、对比度、色度和锐度四种方式增强

程序员文章站 2022-09-21 10:40:27
python中PIL模块中有一个叫做ImageEnhance的类,该类专门用于图像的增强处理,可以实现图像的亮度、对比度、色度和锐度四种方式的增强(或减弱)处理。具体见下面的例子:# -*- coding: UTF-8 -*-import osfrom PIL import Imagefrom PIL import ImageEnhance# 原始图像def ImageAugument(): path = r'E:/PycharmProjects/image_cluster-mast...

python中PIL模块中有一个叫做ImageEnhance的类,该类专门用于图像的增强处理,可以实现图像的亮度、对比度、色度和锐度四种方式的增强(或减弱)处理。
具体见下面的例子:

# -*- coding: UTF-8 -*- import os from PIL import Image from PIL import ImageEnhance # 原始图像 def ImageAugument(): path = r'E:/PycharmProjects/image_cluster-master/data/smoke_call/train/1' # 文件夹目录 files = os.listdir(path) # 得到文件夹下的所有文件名称 # 遍历文件夹 prefix = path + '/' for file in files: # print(file) image = Image.open(prefix + file) # image.show() # 亮度增强 enh_bri = ImageEnhance.Brightness(image) brightness = 1.5 image_brightened = enh_bri.enhance(brightness) image_brightened.save(prefix + file.strip('.jpg') + '-lightup' + '.jpg') # 色度增强 enh_col = ImageEnhance.Color(image) color = 1.5 image_colored = enh_col.enhance(color) image_colored.save(prefix + file.strip('.jpg') + '-colorup' + '.jpg') # 对比度增强 enh_con = ImageEnhance.Contrast(image) contrast = 1.5 image_contrasted = enh_con.enhance(contrast) image_contrasted.save(prefix + file.strip('.jpg') + '-contrastup' + '.jpg') # 锐度增强 enh_sha = ImageEnhance.Sharpness(image) sharpness = 3.0 image_sharped = enh_sha.enhance(sharpness) image_sharped.save(prefix + file.strip('.jpg') + '-moreSharp' + '.jpg') if __name__ == '__main__': ImageAugument() 

效果如下:
python图像处理库ImageEnhance实现图像的亮度、对比度、色度和锐度四种方式增强

本文地址:https://blog.csdn.net/qq_36756866/article/details/108254560