python对图片进行批直方图
import cv2
import matplotlib.pyplot as plt
import os
import numpy as np
def equalize_transfrom(gray_img):
return cv2.equalizeHist(gray_img)
# 读取图片
#源图像路径
imgpath = 'D:/Competiton/mchar_test_a/' #源图像所对应的xml文件路径
rotated_imgpath = 'D:/Competiton/mchar_test_a_1/'
for i in os.listdir(imgpath):
a, b = os.path.splitext(i) #分离出文件名a
img = cv2.imread(imgpath + a + '.png')
b = img[:, :, 0]
g = img[:, :, 1]
r = img[:, :, 2]
b_out = equalize_transfrom(b)
g_out = equalize_transfrom(g)
r_out = equalize_transfrom(r)
equa_out = np.stack((b_out, g_out, r_out), axis=-1)
cv2.imwrite(rotated_imgpath+str(i) +'.png',equa_out)