XYZ到LAB Excel VB脚本

时间:2018-06-08 21:02:55

标签: excel excel-vba math vba

我在使用下面的VBA宏时遇到了一些问题。有人能帮我弄明白我搞砸了吗?

此处引用了计算http://www.brucelindbloom.com/

Public Function LAB_to_XYZ_X(L As Double, A As Double, B As Double) As Double

Dim fx As Double, fx_cubed As Double
Dim fy As Double, fy_cubed As Double
Dim fz As Double, fz_cubed As Double

fy = (L + 16) / 116
fy_cubed = fy * fy * fy
fx = fy + A / 500
fx_cubed = fx * fx * fx
fz = fy - B / 200
fz_cubed = fz * fz * fz

Const LAB_EPSILON = (216 / 24389)
Const LAB_KAPPA = (24389 / 27)

Dim yr As Double, xr As Double, zr As Double

If L > LAB_KAPPA * LAB_EPSILON Then
    yr = fy_cubed
Else:
    yr = L / LAB_KAPPA
End If

If fx_cubed > LAB_EPSILON Then
    xr = fx_cubed
Else:
    xr = (fx * 116 - 16) / LAB_KAPPA
End If

If fz_cubed > LAB_EPSILON Then
    xr = f_zcubed
Else:
    xr = (fx * 116 - 16) / LAB_KAPPA
End If

LAB_to_XYZ_X = xr * D50_WHITE_REF_X
' Y = yr * D50_WHITE_REF_Y
' Z = zr * D50_WHITE_REF_Z

End Function

1 个答案:

答案 0 :(得分:0)

有两个条件,但最后,有一个错误由最后一个决定。

If fx_cubed > LAB_EPSILON Then
    xr = fx_cubed
Else:
    xr = (fx * 116 - 16) / LAB_KAPPA
End If

If fz_cubed > LAB_EPSILON Then '<~~ xr determined by last condition 
    xr = f_zcubed
Else:
    xr = (fx * 116 - 16) / LAB_KAPPA
End If