Skip to content

Commit aa621d6

Browse files
committed
magic constants explained
1 parent 704c688 commit aa621d6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

modules/imgproc/src/color.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7011,6 +7011,8 @@ struct RGB2Luv_b
70117011
const float* _whitept, bool _srgb )
70127012
: srccn(_srccn), cvt(3, blueIdx, _coeffs, _whitept, _srgb)
70137013
{
7014+
//0.72033 = 255/(220+134), 96.525 = 134*255/(220+134)
7015+
//0.9732 = 255/(140+122), 136.259 = 140*255/(140+122)
70147016
#if CV_NEON
70157017
v_scale_inv = vdupq_n_f32(1.f/255.f);
70167018
v_scale = vdupq_n_f32(2.55f);
@@ -7211,6 +7213,8 @@ struct Luv2RGB_b
72117213
const float* _whitept, bool _srgb )
72127214
: dstcn(_dstcn), cvt(3, blueIdx, _coeffs, _whitept, _srgb )
72137215
{
7216+
// 1.388235294117647 = (220+134)/255
7217+
// 1.027450980392157 = (140+122)/255
72147218
#if CV_NEON
72157219
v_scale_inv = vdupq_n_f32(100.f/255.f);
72167220
v_coeff1 = vdupq_n_f32(1.388235294117647f);

modules/imgproc/src/opencl/cvtcolor.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,9 @@ __kernel void BGR2Luv(__global const uchar * src, int src_step, int src_offset,
20352035
float v = L*fma(2.25f, Y*d, -_vn);
20362036

20372037
dst[0] = SAT_CAST(L * 2.55f);
2038+
//0.72033 = 255/(220+134), 96.525 = 134*255/(220+134)
20382039
dst[1] = SAT_CAST(fma(u, 0.72033898305084743f, 96.525423728813564f));
2040+
//0.9732 = 255/(140+122), 136.259 = 140*255/(140+122)
20392041
dst[2] = SAT_CAST(fma(v, 0.9732824427480916f, 136.259541984732824f));
20402042

20412043
++y;
@@ -2137,7 +2139,9 @@ __kernel void Luv2BGR(__global const uchar * src, int src_step, int src_offset,
21372139
{
21382140
float d, X, Y, Z;
21392141
float L = src[0]*(100.f/255.f);
2142+
// 1.388235294117647 = (220+134)/255
21402143
float u = fma(convert_float(src[1]), 1.388235294117647f, -134.f);
2144+
// 1.027450980392157 = (140+122)/255
21412145
float v = fma(convert_float(src[2]), 1.027450980392157f, - 140.f);
21422146
if(L >= 8)
21432147
{

0 commit comments

Comments
 (0)