import os
import cv2 as cv
import matplotlib.pyplot as plt # plt 用于显示图片
import matplotlib.image as mpimg # mpimg 用于读取图片
def hisEqulColor1(img):
ycrcb = cv.cvtColor(img, cv.COLOR_BGR2YCR_CB)
channels = cv.split(ycrcb)
# 以下代码详细注释见官网:
# https://docs.opencv.org/4.1.0/d5/daf/tutorial_py_histogram_equalization.html
clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
clahe.apply(channels[0], channels[0])
cv.merge(channels, ycrcb)
cv.cvtColor(ycrcb, cv.COLOR_YCR_CB2BGR, img)
return img
all_folds = os.listdir(r'C:\Users\XYL\PycharmProjects\UI\test1\pic')
print(all_folds[1])
a=all_folds.__len__()
i=0
while i<a:
img1 = cv.imread(r'C:\Users\XYL\PycharmProjects\UI\test1\pic\{}'.format(all_folds[i]))
# cv.imwrite(r'C:\Users\XYL\PycharmProjects\UI\test1\a_pic', img1)
a1=hisEqulColor1(img1)
cv.imwrite(r'C:\Users\XYL\PycharmProjects\UI\test1\a_pic\{}.jpg'.format(i), a1)
i+=1
opencv 批量读取图片、处理,并批量保存