当前位置:网站首页>利用七种方法对一个文件夹里面的所有图像进行图像增强实战

利用七种方法对一个文件夹里面的所有图像进行图像增强实战

2022-07-07 15:40:00 AI炮灰

# coding = utf-8
import cv2
from PIL import Image
from PIL import ImageEnhance
from numpy.ma import array
import numpy as np
import os
# 批量处理代码
rootdir = 'F:/danzi/数据/4' # 指明被遍历的文件夹

def high_bright(currentPath, filename, targetPath):
    # 读取图像
    image = Image.open(currentPath)
    image_cv = cv2.imread(currentPath)
    # image.show()
    # 增强亮度 bh_
    enh_bri = ImageEnhance.Brightness(image)
    brightness = 1.07
    image_brightened_h = enh_bri.enhance(brightness)
    # image_brightened_h.show()
    image_brightened_h.save(targetPath+ '1' + filename)  # 保存

def low_bright(currentPath, filename, targetPath):
    image = Image.open(currentPath)
    image_cv = cv2.imread(currentPath)
    # 降低亮度 bl_
    enh_bri_low = ImageEnhance.Brightness(image)
    brightness = 0.87
    image_brightened_low = enh_bri_low.enhance(brightness)
    # image_brightened_low.show()
    image_brightened_low.save(targetPath&#
原网站

版权声明
本文为[AI炮灰]所创,转载请带上原文链接,感谢
https://blog.csdn.net/bigData1994pb/article/details/124985252