opencv 批量读取图片、处理,并批量保存

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 批量读取图片、处理,并批量保存

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值