Generating Reflectance Curves from sRGB Triplets (Page 10)

Update 6/4/2019: I’ve just developed a new method that gives even better natural-reflectance-matching results than the ILLSS method above, with considerably less computational effort required (comparable to that of LLSS). Here it is:

Least Hyperbolic Tangent Slope Squared (LHTSS) Method

Recall that the Least Log Slope Squared (LLSS) method generates reflectance curves that are strictly positive, without requiring explicit bounds in the optimization statement. The lower bound is handled implicitly in the logarithmic transformation. This section presents a newly developed approach to generate reflectances that are strictly within the 0-1 range, also not needing explicit bounds. Why is this useful? The methods that use explicit bounds (presented above: ILSS and ILLSS) tend to have abrupt discontinuities in slope when a bounding constraint is engaged. This makes the reflectance curves seem somewhat unnatural. The LHTSS method described in this section makes reflectance curves that gently approach the upper and/or lower bounds, and match the reflectance curves of commercial paints and pigments even better than any of the previous methods above.

The Least Hyperbolic Tangent Slope Squared (LHTSS) method uses a transformation defined by

    \[\rho = \frac{\mathrm{tanh}(z)+1}{2}\]

to keep all reflectance values between 0 and 1. Below is a plot of the hyperbolic tangent function:

Hyperbolic Tangent

(Click to enlarge.)

Note how the curve approaches +1/-1 as z grows large in either the positive or negative directions. By adding 1 to tanh and then dividing by 2, the upper and lower bounds shift to 1 and 0. This causes the reflectances to remain strictly between 0 and 1 for any value of z:

LHTSS Transformation

(Click to enlarge.)

The least slope optimization statement for the Hyperbolic Tangent Slope Squared method is:

    \[\begin{split}\mathsf{minimize}\;\;&\sum_{i=1}^{35} (z_{i+1} - z_i)^2 \\ \mathsf{s.t.}\;\;&T \left\{\frac{\mathrm{tanh}(z)+1}{2}\right\} = rgb.\end{split}\]

Noting that the first derivative of \mathrm{tanh}(z) is \mathrm{sech}^2(z), the stationary conditions of the Lagrangian function associated with this optimization comprise a system of 39 nonlinear equations and 39 unknowns:

    \[F=\begin{Bmatrix}D z + \mathrm{diag}(\mathrm{sech}^2(z)/2)\;T^\mathsf{T} \lambda \\ T\;(\mathrm{tanh}(z)+1)/2 - rgb \end{Bmatrix} = \begin{Bmatrix}0\\0\end{Bmatrix},\]

where D is the 36\mathsf{x}36 tridiagonal matrix of finite differencing constants presented earlier.

Newton’s method solves this system of equations with ease, typically in a fairly small number iterations. Noting that the first derivative of \mathrm{sech}^2(z)/2 is -\mathrm{sech}^2(z) \mathrm{tanh}(z), the Jacobian matrix of first partial derivatives of F is

    \[J=\left[\begin{array}{c|c} D - \mathrm{diag}(\mathrm{diag}(\mathrm{sech}^2(z) \mathrm{tanh}(z))\;T^\mathsf{T} \lambda) & \mathrm{diag}(\mathrm{sech}^2(z)/2)\;T^\mathsf{T} \\ \hline T\;\mathrm{diag}(\mathrm{sech}^2(z)/2) & 0 \end{array}\right].\]

The change in the variables with each Newton iteration is found by solving the linear system

    \[J\;\begin{Bmatrix}\Delta z\\ \Delta \lambda \end{Bmatrix} = -F.\]

At each iteration, the values of z and \lambda are updated using z^{k+1}=z^k+\Delta z and \lambda^{k+1}=\lambda^k+\Delta \lambda.

Here is a Matlab program for the LHTSS (Least Hyperbolic Tangent Slope Squared) method. It also works in the free Octave software. It handles the two cases of sRGB = (0,0,0) and (255,255,255) specially, since the reflectance curves associated with them fall outside the strict interval (0->1) imposed by the hyperbolic tangent transform.

If you prefer not to work in a programming environment, here is an Excel spreadsheet that implements the LHTSS method. Just follow the instructions at the top of the spreadsheet. It uses the “Solver” add-in within Excel, which you may need to load. Here are instructions for doing that.

An example of how this hyperbolic tangent method (LHTSS) compares to the logarithmic method (LLSS) and the regular least slope squared method (LSS), when applied to the Munsell color 7.5R 5/16, is shown in the figure below.

Munsell 7.5R 5/16 (purple) compared to LSS (red), LLSS (orange), and LHTSS (blue). (Click to enlarge.)

This figure demonstrates an instance where LSS has negative elements, LLSS has elements >1, and LHTSS corrects both of these deficiencies. It is quite striking how well the LHTSS reconstruction matches the measured reflectance curve of this particular Munsell chip.

To check just how well the curves produced by LHTSS compare to the reflectance curves measured from 1296 Munsell chip colors, the “reflectance match measure, RMM” was computed and added to the previous table:

Name Max RMM Mean RMM
LLS, Linear Least Squares 2.46 0.88
LSS, Least Slope Squared 1.11 0.17
ILSS, Iterative Least Slope Squared 1.04 0.16
LLSS, Least Log Slope Squared 0.92 0.15
ILLSS, Iterative Least Log Slope Squared 0.86 0.15
LHTSS, Least Hyperbolic Tangent Slope Squared 0.84 0.14

It is evident that LHTSS performs the best of all methods with regard to the comparison to Munsell reflectance curves.

The computational effort required for the LHTSS method is comparable to that of LLSS. The computational effort study performed above, using 140,608 sRGB triplets (every value possible in intervals of five), showed that the LLSS method required 6.77 iterations on average. The LHTSS method requires an average of 5.66 iterations, so its average run times are somewhat smaller (approx 5%).

Update 1/18/20: These methods (including the new LHTSS method) have been published in a paper called “Numerical Methods for Smoothest Reflectance Reconstruction,” in the journal Color Research and Application (citation: Burns SA. Numerical methods for smoothest reflectance reconstruction. Color Res Appl. 2020;45(1):8-21). Contact me if you’d like a copy of this paper.



This work has been a tremendous learning experience for me, and I want to thank several people who graciously posted high quality material, upon which most of my work has been based: Bruce Lindbloom, Bruce MacEvoy, Zsolt Kovacs-Vajna, David Briggs, and Paul Centore. If you are interested in learning more about color theory, these five links are excellent places to start!


Creative Commons License
Generating Reflectance Curves from sRGB Triplets by Scott Allen Burns is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.



The presentation is spread over several web pages. Click the Next Page or Previous Page links to move sequentially. To access a page directly, use these links:

1. Introduction
2. Computing an sRGB triplet from a Reflectance Curve
3. Linear Least Squares (LLS) Method
4. Least Slope Squared (LSS) Method
5. Least Log Slope Squared (LLSS) Method
6. Iterative Least Log Slope Squared (ILLSS) Method
7. Iterative Least Slope Squared (ILSS) Method
8. Comparison of Methods
9. Conclusions (pre-6/4/19)
10. Update 6/4/19: Least Hyperbolic Tangent Slope Squared (LHTSS) Method (this page)

← Previous Page