当前位置:网站首页>Use seven methods to enhance all the images in a folder

Use seven methods to enhance all the images in a folder

2022-07-07 17:40:00 AI cannon fodder

# coding = utf-8
import cv2
from PIL import Image
from PIL import ImageEnhance
from numpy.ma import array
import numpy as np
import os
#  Batch processing code 
rootdir = 'F:/danzi/ data /4' #  Indicates the folder being traversed 

def high_bright(currentPath, filename, targetPath):
    #  Read images 
    image = Image.open(currentPath)
    image_cv = cv2.imread(currentPath)
    # image.show()
    #  Enhance the brightness  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)  #  preservation 

def low_bright(currentPath, filename, targetPath):
    image = Image.open(currentPath)
    image_cv = cv2.imread(currentPath)
    #  Decrease brightness  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 cannon fodder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071529540358.html