CLAHE处理,灰度化后批量保存图片

import os

import cv2

import numpy as np

import sys

if __name__=="__main__":

    path1='./best/'

    path2='./newgray/'

    pictures = []

    for root, dirs, files in os.walk(path1):

        for f in files:

            pictures.append(os.path.join(root,f))

    i=1

    for dir in pictures:

        print(dir)

        s=cv2.imread(dir,cv2.IMREAD_ANYCOLOR)

        clahe=cv2.createCLAHE(clipLimit=2.0,tileGridSize=(7,7))

        gray_image=cv2.cvtColor(s,cv2.COLOR_BGR2GRAY)

        dst=clahe.apply(gray_image)

        cv2.imwrite(".//newgray//{}.png".format(str(i)),gray_image)

        i+=1






2.

import cv2

import numpy as np

import sys

if __name__=="__main__":

    if len(sys.argv)>1:

        src=cv2.imread(sys.argv[1],cv2.IMREAD_ANYCOLOR)

    else:

        print("请输入图像:")

    clahe=cv2.createCLAHE(clipLimit=2.0,tileGridSize=(8,8))

    gray_image=cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)

    dst=clahe.apply(gray_image)

    cv2.imshow("原图",src)

    cv2.imshow("灰度图:",gray_image)

    cv2.imshow("直方图均衡化",dst)

    cv2.waitKey(0)

    cv2.destroyAllWindows()

你可能感兴趣的:(CLAHE处理,灰度化后批量保存图片)