python中的反γ校正

2024-03-29 05:03:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用

import cv2

def adjust_gamma(image, gamma=1.0):
    # build a lookup table mapping the pixel values [0, 255] to
    # their adjusted gamma values
    invGamma = 1.0 / gamma
    table = np.array([((i / 255.0) ** invGamma) * 255
        for i in np.arange(0, 256)]).astype("uint8")

    # apply gamma correction using the lookup table
    return cv2.LUT(image, table)

为了进行反伽马校正,但我的数据是[04095]格式的,所以我修改了代码,将255替换为4095,256替换为4096:

^{pr2}$

但是在尝试对随机png图像调用函数时:

adjust_gamma(cv2.imread('myimage.png'), gamma=2.0)

我得到了一个错误:

OpenCV(3.4.3) /io/opencv/modules/core/src/lut.cpp:368: error: (-215:Assertion failed) (lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == CV_8U || depth == CV_8S) in function 'LUT'

Tags: theinimagepngnptablelookupcv2
1条回答
网友
1楼 · 发布于 2024-03-29 05:03:55

从高层次上讲,我认为您的问题只是方法兼容性的问题:LUT使用标准的8位格式。在将图像输入方法之前,必须将其转换为该格式。或者,您可以编写自己的12位LUT方法,用4095/4096替换原始代码中的所有上限。在

相关问题 更多 >