【发布时间】:2018-08-19 16:27:37
【问题描述】:
假设我们有一个图像内 5 个圆圈的 l,a,b 值。这些值是使用 OpenCV 计算得出的。
imlab=cv2.cvtColor(circle_img_only,cv2.COLOR_BGR2LAB).astype("float32")
实际上,我们从每个圆圈中抽取 100 个随机像素并计算每个圆圈的正常平均 LAB 值(我不确定这是正确的做法)
值是 np.array,类似于以下内容:
LAB Measured Colors Values =
[[ 27.553 -26.39 7.13 ]
[ 28.357 -27.08 7.36 ]
[ 28.365 -27.01 7.21 ]
[ 29.749 -27.78 7.42 ]
[ 28.478 -26.81 7.14 ]]
这些圆圈也是使用色度计测量的。色度计生成一个参考值。
LAB Reference Colors Values =
[35.07, -24.95, 3.12]
[35.09, -24.95, 3.18]
[35.0, -25.6, 3.21]
[34.97, -25.76, 3.36]
[35.38, -24.55, 2.9]
让我们将 LAB 测量颜色值称为 m1 让我们将 LAB 参考颜色值称为 m2
我们有测量值和参考值。 我们如何计算 CCM - 颜色校正矩阵?
我使用以下方法:
def first_order_colour_fit(m_1, m_2 , rcond=1):
"""
Colour Fitting
==============
Performs a first order colour fit from given :math:`m_1` colour array to
:math:`m_2` colour array. The resulting colour fitting matrix is computed
using multiple linear regression.
The purpose of that object is for example the matching of two
*ColorChecker* colour rendition charts together
Parameters
----------
m_1 : array_like, (3, n)
Test array :math:`m_1` to fit onto array :math:`m_2`.
m_2 : array_like, (3, n)
Reference array the array :math:`m_1` will be colour fitted against.
Simply: Creating and clculating CCM - Color Correction Matrix
"""
print('CCM - Color Correction Matrix = ')
ColorCorrectionMatrix = np.transpose(np.linalg.lstsq(m_1, m_2 , rcond)[0])
这会生成:
CCM - Color Correction Matrix =
[[-0.979 -2.998 -2.434]
[ 0.36 1.467 0.568]
[ 0.077 0.031 0.241]]
获得 CCM 后 - 我想在 m1(LAB 测量颜色)上应用 CCM,并更正它们。
我们该怎么做?
我正在执行以下操作,但结果似乎不好:
def CorrectedMeasuredLABValues(measured_colors_by_app , ColorCorrectionMatrix , reference_LAB_colors_values ):
CorrectedMeasured_LAB_Values = np.zeros_like(measured_colors_by_app , dtype=object)
print('\n\n\n\n Corrected Measured LAB Values Matrix = ')
for i in range(measured_colors_by_app.shape[0]):
print(ColorCorrectionMatrix.dot(measured_colors_by_app[i]))
CorrectedMeasured_LAB_Values[i] = ColorCorrectionMatrix.dot(measured_colors_by_app[i])
我们得到以下信息:
Corrected Measured LAB Values Matrix =
[ 34.766 -24.742 3.033]
[ 35.487 -25.334 3.129]
[ 35.635 -25.314 3.096]
[ 36.076 -25.825 3.23 ]
[ 35.095 -25.019 3.094]
【问题讨论】:
-
是的,您可以取 Lab 值的正常平均值。
-
谢谢。总和(LAB 中的所有随机像素)/像素数?
-
可以,只要总和分别超过 L、a 和 b 的值。
-
当然。谢谢我们可以像我在问题中详述的那样从 LAB 值创建 CCM,还是应该为此使用归一化的 RGB 值?
-
我需要坐在电脑后面尝试一些事情,然后才能回答您的其余问题。原则上,在 Lab 空间中进行校正没有任何问题,尽管在 RGB 中这样做效率更高(因为转换为 Lab 相对昂贵)。
标签: python-3.x image-processing opencv3.0