我写了一些代码对图像进行伽马校正。为了做到这一点,我正在创建一个LUT来执行图像中的伽马校正。调用cv2.LUT时,收到以下错误
C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-52oirelq\opencv\modules\core\src\lut.cpp:368:错误:(-215:断言失败)函数'cv::LUT‘中的
错误(lutcn == cn区cn\x lutcn == 1) & _lut.total() == 256 & _lut.isContinuous()和(深度== CV_8U _lut.isContinuous_lut.isContinuous == CV_8S)
我编写的代码如下所示,它是执行伽马校正的函数:
import cv2
import numpy as np
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)我做错了什么?
发布于 2020-10-22 18:37:04
您的输入图像很可能不是无符号8位整数。错误消息非常有说服力,因为它希望cv2.LUT中的输入映像是这种类型。我怀疑你的图像是浮点精度。在这种情况下,最简单的解决方案是将值缩放为255,然后强制转换为uint8,然后运行该方法,然后将其转换为浮点:
output = adjust_gamma((255 * image).astype(np.uint8), table)
output = (output.astype(np.float)) / 255https://stackoverflow.com/questions/64484423
复制相似问题