opencv学习25——图像亮度增强

一、

图像亮度增强

1.实现过程:对每个像素点的三通道值进行同步放大,同时保持通道值在0-255之间

2.map(f,list),将函数f作用于整个列表,返回新列表

3.np.clip(a, a_min, a_max, out=None),将a中的元素限制在最小值和最大值之间,超过此区间的值赋值为最小值或最大值

二、

import cv2
import numpy as np

def enhance_mycode(img):
    imgHeight,imgWidth,imgDeep = img.shape
    dst1 = np.zeros((imgHeight, imgWidth, 3), np.uint8)

    for i in range(0, imgHeight):
        for j in range(0, imgWidth):
            (b, g, r) = map(int,img[i,j])
            b += 40
            g += 40
            r += 40
            if b > 255:
                b = 255
            if g > 255:
                g = 255
            if r > 255:
                r = 255
            dst1[i, j] = (b, g, r)
    return dst1
def enhance_api(img):
    dst2 = np.uint8(np.clip((1.5 * img ), 0, 255))
    return dst2

img = cv2.imread('image01.jpg',1)
dst1 = enhance_mycode(img)
dst2 = enhance_mycode(img)

cv2.imshow('src', img)
cv2.imshow('dst1', dst1)
cv2.imshow('dst2', dst2)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

你可能感兴趣的:(opencv)