首页 > 其他分享 >cv-调节亮度代码

cv-调节亮度代码

时间:2022-11-03 22:02:23浏览次数:62  
标签:plt name img 代码 cv2 亮度 lol path cv

第一版

import sys
import cv2
import numpy as np
from matplotlib import pyplot as plt

def imgBrightness(img1, c, b): 
    rows, cols, channels = img1.shape
    blank = np.zeros([rows, cols, channels], img1.dtype)
    rst = cv2.addWeighted(img1, c, blank, 1-c, b)
    return rst

 
if __name__ == "__main__":
    print("PY file argv is:", sys.argv[1])
    path = sys.argv[1]          # 获取文件名字
    img = cv2.imread(path)      # 读取图片
    img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)    # 转换成灰度图
    img_gray = img_gray.reshape(-1)  #将图像展开成一个一维的numpy数组
    plt.hist(img_gray, 128)          #将数据分为128组
    firstName = path[:-4]
    secondName = path[-4:]
    name = firstName + '_hist' + secondName
    plt.savefig(name)
    
    # 调整后图像保存
    img_lol_1 = img
    img_lol_1 = imgBrightness(img_lol_1, 1.5, 0)
    #plt.hist(img_lol_1, 128)          #将数据分为128组
    firstName = path[:-4]
    secondName = path[-4:]
    name = firstName + '_img_lol_2' + secondName
    #plt.savefig(name)
    cv2.imwrite(name, img_lol_1)
    

标签:plt,name,img,代码,cv2,亮度,lol,path,cv
From: https://www.cnblogs.com/starcos/p/16855993.html

相关文章