【发布时间】:2018-03-05 13:43:01
【问题描述】:
我一直在尝试实现以下提供的白平衡算法: https://pippin.gimp.org/image-processing/chapter-automaticadjustments.html
我已经使用 python 和 opencv 来实现它们。我无法产生与网站相同的结果。
在灰色世界假设中,例如,我使用以下代码:
import cv2 as cv
import numpy as np
def show(final):
print 'display'
cv.imshow("Temple", final)
cv.waitKey(0)
cv.destroyAllWindows()
def saveimg(final):
print 'saving'
cv.imwrite("result.jpg", final)
# Insert any filename with path
img = cv.imread("grayworld_assumption_0.png")
res = img
final = cv.cvtColor(res, cv.COLOR_BGR2LAB)
avg_a = -np.average(final[:,:,1])
avg_b = -np.average(final[:,:,2])
for x in range(final.shape[0]):
for y in range(final.shape[1]):
l,a,b = final[x][y]
shift_a = avg_a * (l/100.0) * 1.1
shift_b = avg_b * (l/100.0) * 1.1
final[x][y][1] = a + shift_a
final[x][y][2] = b + shift_b
final = cv.cvtColor(final, cv.COLOR_LAB2BGR)
final = np.hstack((res, final))
show(final)
saveimg(final)
我得到了结果
我哪里错了?
【问题讨论】:
-
cv.imread()是否默认为 BGR?我曾假设它使用 RGB,但我现在找不到文档。这可能是问题吗? ...NVM 找到了文档,默认使用 BGR。 -
@norok 它在docs.opencv.org/3.0-beta/modules/imgcodecs/doc/… 中说,“在彩色图像的情况下,解码后的图像将具有以 B G R 顺序存储的通道。”
标签: python opencv numpy image-processing