Algorithmic Improvements for the CIECAM02 and CAM16 Color
Total Page:16
File Type:pdf, Size:1020Kb
Algorithmic improvements for the CIECAM02 and CAM16 color appearance models∗ Nico Schlömer February 19, 2018 This note is concerned with the CIECAM02 In both CIECAM02 and its updated version color appearance model and its successor, the CAM16, some of the steps are more compli- CAM16 color appearance model. Several al- cated than necessary, and in edge cases lead gorithmic flaws are pointed out and remedies to break downs once again. The present doc- are suggested. The resulting color model is al- ument describes those flaws and suggests im- gebraically equivalent to CIECAM02/CAM16, provements (Section 2). The resulting model but shorter, more efficient, and works correctly description (Section A) is entirely equivalent to for all edge cases. the CIECAM02/CAM16, but is simpler – hence faster and easier to implement – and works in all edge cases. 1. Introduction All findings in this article are implemented in the open-source software package colorio [4]. The CIECAM02 color appearance model [3] has attracted much attention and was generally thought of as a successor to the ever so popular 2. Flaws and fixes CIELAB color model. However, it was quickly This section describes the flaws of CAM16 and discovered that CIECAM02 breaks down for suggests fixes for them. Some of them are triv- certain input values. A fair number of research ial, others are harder to see. All listed steps articles suggests fixes for this behavior, most also appear in the CIECAM02 color appear- of them by modifying the first steps of the for- ance model and trivially apply there. ward model. Luo and Li give an overview of the suggested improvements [2]; see references therein. Most recently, Li and Luo [1] gave their 2.1. Step 3, forward model own suggestion on how to best circumvent the The original Step 3 of the forward model reads breakdown [1]. The updated algorithm differs arXiv:1802.06067v1 [eess.IV] 16 Feb 2018 from the original CIECAM02 only in the first Step 3. Calculate the postadaptation cone re- steps of the forward model. sponse (resulting in dynamic range compres- It appears that that the rest of the algorithm sion). 0.42 has not received much attention over the years. FL Rc 100 R = 400 + 0.1 ∗The LaTeX sources of this article are on a 0.42 FL Rc + https://github.com/nschloe/note-on-cam16 100 27.13 1 with fixes without 2.2. Linear combinations, forward model J 0.0 3.258e-22 C 0.0 4.071e-24 h 0.0 0.0 In the forward model, four linear combinations Q 0.0 2.233e-10 of Ra′ , Ga′ , and Ba′ have to be formed. They can M 0.0 2.943e-24 conveniently be expressed as the matrix-vector s 0.0 1.148e-05 multiplication Table 1: CAM16 values upon input X = Y = Z = 1 0 with and without the fixes in p2′ 2 1 20 R this article. The exact solutions are a 1 12 1 a′ ≔ 11 11 zeros for every entry. 1 −1 2 Ga′ © b ª © 9 9 9 ª ® − ® Ba′ ® 21 ® © ª u ® 1 1 ® ® ® 20 ® If Rc is negative, then « ¬ « ¬ « ¬ 0.42 FL Rc which on many platforms can be computed − 100 R = 400 + 0.1 significantly faster than four individual dot- a 0.42 − FL Rc + products. The last variable u is used in the − 100 27.13 computation of t in step 9. and similarly for the computations of Ga and Ba. If the sign operator is used here as it is used later in step 5 of the inverse model, the above 2.3. Step 9, forward model description can be shortened. Furthermore, the term 0.1 is added here, but Step 9. Calculate the correlates of [. ] satu- in all of the following steps in which Ra is used ration (s). – except the computation of t in Step 9 –, it can- cels out algebraically. Unfortunately, said can- s ≔ 100 M Q. cellation is not always exact when computed in / floating point arithmetic. Luckily, the adverse p effect of such rounding errors is rather limited here. The results will only be distorted for very This expression is not well-defined if Q = 0, = = = small input values, e.g., X Y Z 0; see Ta- a value occurring if the input values are X = ble 1. For the sake of consistency, it is advisable Y = Z = 0. When making use of the definition to include the term 0.1 only in the computation of M and Q, one gets to an expression for s that of t in Step 9: is well-defined in all cases: 0.42 FL Rc 100| | R = 400 sign R . 0.9 n 0.73 a′ c 0.42 α ≔ t 1.64 0.29 , (1) ( ) FL Rc | | + 27.13 ( − ) 100 cα s ≔ 50 . r Aw + 4 2 2.4. Steps 2 and 3, inverse model It turns out that both of these problems can be avoided quite elegantly. Consider, in the case Step 2. Calculate t, et , p1, p2, and p3. sin h cos h : | ( )| ≥| ( )| 1 . 0 9 ≔ 50000 C p1′ Nc Ncb et, t = , 13 J n 0.73 + 460 © 1.64 0.29 ª p2 2 p3 1403 100 ( − ) ® b = ( ) q p′ 220 cos h 27 6300 1 ® 1 + 2 + p ( ) + p = + + t sin h 3 1403 sin h 1403 3 1403 et « cos h′π 180° 2 3¬.8 , ( ) ( ) ( ) − 4 [ ( / ) ] t sin h p 2 + p 460 = 2 3 1403 = 50000 1 ( ) ( ) p1 Nc Ncbet , p + t 2 + p 220 cos h + t sin h 6588 13 t 1′ ( 3) 1403 ( ) ( ) 1403 A 23t sin h p2 p2 = + 0.305, = ( ) , N + + bb 23p1′ 11t cos h 108t sin h 21 ( ) ( ) p = . 3 20 and = 23t cos h p2 Step 3. Calculate a and b. If t 0, then a = ( ) . = = 23p + 11t cos h + 108t sin h a b 0 and go to Step 4. In the next com- 1′ ( ) ( ) putations be sure transform h from degrees to Conveniently, the exact same expressions are radians before calculating sin h and cos h : If ( ) ( ) retrieved in the case cos h > sin h . These sin h cos h then | ( )| | ( )| | ( )| ≥ | ( )| expressions are always well-defined since p p = 1 , 4 + + sin h 23p1′ 11t cos h 108t sin h ( ) 460 ( ) ( ) p2 2 + p3 23p′ p2 b = ( ) 1403 , = 1 > 0. + + 220 cos h 27 + 6300 R + G + 21 B + 0.305 p4 2 p3 1403 sin(h) 1403 p3 1403 a′ a′ 20 a′ ( ) ( ) − cos h a = b ( ). In the algorithm, the value of t can be re- sin h ( ) trieved via α (1) from the input variables. In- deed, if the saturation correlate s is given, one If cos h > sin h then | ( )| | ( )| has s 2 A + 4 p1 α ≔ w ; p5 = , cos h 50 c ( ) . p 2 + p 460 if M is given, one can compute C ≔ M F0 25 = 2 3 1403 / L a ( ) , and then + + 220 27 6300 sin h p5 2 p3 1403 1403 p3 1403 cos(h) ( ) − − ( ) = sin h 0 if J 0, b = a ( ) . ≔ cos h α C ( ) otherwise. J 100 / Some of the complications in this step stem p from the fact that the variable t might be 0 in the It is mildly unfortunate that one has to intro- denominator of p1. Likewise, the distinction of duce a case distinction for J = 0 here, but this cases in sin h and cos h is necessary to avoid is an operation that can still be performed at ( ) ( ) division by 0 in a and b. reasonable efficiency. 3 2 without fixes • Luminance of test adapting field (cd m− ): 0.6 with fixes LA. LA is computed using EW Yb LWYb 0.4 LA = = , π YW YW 0.2 Time in seconds where EW = πLW is the illuminance of reference white in lx; LW is the luminance 2 0 of reference white in cd m− ; Yb is the lu- 0 0.2 0.4 0.6 0.8 1 minance factor of the background; and Yw Number of input samples 106 is the luminance factor of the reference · white. Figure 1: Performance comparison of the con- version from CAM16 to XYZ (with J, C, and h), implemented in colorio [4]. • Surround parameters are given in Table 2: The suggested improvements in the To determine the surround conditions see inverse model lead to a speed-up of the note at the end of Part 1 of Appendix about 5%. A of [1]. A. Full model • Nc and F are modelled as a function of c, and their values can be linearly interpo- For the convenience of the reader, both forward lated, using the data from 2. and inverse steps of the improved CAM16 al- gorithm are given here. The wording is taken from [1] where applicable. The steps that dif- Let M16 be given by fer from the original model are marked with an asterisk (*). R 0.401288 0.650173 0.051461 As an abbreviation, the bold letter is used − M ≔ 0.250268 1.204414 0.045854 . whenever the equation applies to R, G, and B 16 − alike. © 0.002079 0.048952 0.953127 ª − ® « ¬ Illuminants, viewing surrounds set up and background parameters (See the note at the A.1. Forward model end of Part 2 of Appendix B of [1] for determin- ing all parameters.) Step 0*. Calculate all values/parameters which are independent of the input sample. • Adopted white in test illuminant: Xw, Yw, Zw Rw Xw • Background in test conditions: Yb Gw = M16 Yw , • Reference white in reference illuminant: ©Bw ª ©Zwª X = Y = Z = 100, fixed in the ® ® wr wr wr D = F 1 1 exp La 42 .