Python批量处理图片对比度并且保存

在别人帖子上进行了改进,加入了读取文件夹下的图片并进行批量处理并保存的模块

import cv2
import sys
import os
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
"""
  对比度调整算法:
  主要是对RGB空间进行调整。设定合适的RGB阈值,并在此阈值基础上计算出合适的调整系数进行对比度调整。
  参考CSDN博客:https://blog.csdn.net/maozefa/article/details/7069001
"""
def ContrastAlgorithm(rgb_img, contrast=0.5, threshold=0.5):
    img = rgb_img * 1.0
    img_out = img
    # 增量等于1,按灰度阈值最多调整成八种颜色:
    # 黑、红、绿、蓝、黄(255,255,0)、品红(255,0,255)、青(0,255,255)、白
    if contrast == 1:
        # newRGB = RGB >= Threshold? 255 : 0
        mask_1 = img >= threshold * 255.0
        rgb1 = 255.0
        rgb2 = 0
        img_out = rgb1 * mask_1 + rgb2 * (1 - mask_1)
    # 增量大于0小于1
    elif contrast >= 0:
        alpha = 1 - contrast
        alpha = 1 / alpha - 1
        img_out[:, :, 0] = img[:, :, 0] + (img[:, :, 0] - thres
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值