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) 


全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 14:35
点赞 评论 收藏
分享
05-07 19:10
已编辑
中国科学技术大学 C++
silly01:现在先去 momenta,8-9月去鹅找日常实习,八股文算法背好了你这随便进。不过建议补充一下后端知识,MySQL、Redis看下八股,再补个6824,加点go后台的技术栈,9月随便进大厂。CPP后端只能来WXG
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务