Conversion of CIELab to CIELCh(ab) not yielding correct result

懵懂的女人 提交于 2020-06-23 14:46:06

问题


I am having a hard time manually converting CIELab to CIELCh with my calculator.

According to http://www.easyrgb.com/en/math.php, the following is a neutral language programming code to get from CIELab to CIELCh by going from radians to degrees:

var_H = arc_tangent( CIE-b*, CIE-a* )  //Quadrant by signs
if ( var_H > 0 ) var_H = ( var_H / PI ) * 180
else             var_H = 360 - ( abs( var_H ) / PI ) * 180
CIE-L* = CIE-L*
CIE-C* = sqrt( CIE-a* ^ 2 + CIE-b* ^ 2 )
CIE-H° = var_H

And on this website, it gives the same code but assumes everything is already in degrees: http://www.brucelindbloom.com/index.html?Equations.html

When attempting to convert CIELAB code (37.80, -21.59, 38.17) to CIELch via my physical handheld calculator, I get the value (38, 43.851, 299.49).

However, the correct value is (38, 43.851, 119.499).

This means that everything is good for the first two parts, but the last part is incorrect.

I don't understand how they obtained 119 instead of 299. I believe there may be an error in the math. The following is how I was able to retrieve 299 via a calculator:

I took the arctangent of (38.17/-21.59). I retrieved the value of -1.056 radians. According to the code, if var_H < 0, then you need to do:

 var_H = 360 - ( abs( var_H ) / PI ) * 180

So I did 360 - (1.056/3.14)*180.

And that gives 299.

So what am I doing wrong here? How do I get value of 119???


回答1:


I contacted the EasyRGB website's support and they were awesome enough to explain what to do! This is what the representative stated:

You need to consider the "quadrants" in your arctangent calculation. This is an example to calculate the H° value from CIE-Lab keeping the quadrant info in mind:

FUNCTION GS_CIE2Hue( a, b )
LOCAL xBias
if a >= 0 .AND. b == 0 ; return 0     ; endif
if a <  0 .AND. b == 0 ; return 180   ; endif
if a == 0 .AND. b >  0 ; return 90    ; endif
if a == 0 .AND. b <  0 ; return 270   ; endif
if a >  0 .AND. b >  0 ; xBias := 0   ; endif
if a <  0              ; xBias := 180 ; endif
if a >  0 .AND. b <  0 ; xBias := 360 ; endif
return rtod( atan( b / a ) ) + xBias

All credit to this solution goes to http://www.easyrgb.com. If anyone is attempting to convert any colors, they should definitely check out their calculator and math page:

http://www.easyrgb.com/en/convert.php#inputFORM

http://www.easyrgb.com/en/math.php



来源:https://stackoverflow.com/questions/53733379/conversion-of-cielab-to-cielchab-not-yielding-correct-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!