Generating Reflectance Curves from sRGB Triplets (Page 2)


sRGB Triplet from a Reflectance Curve

The reverse process of computing an sRGB triplet from a reflectance curve is straightforward. It requires two main components: (1) a mathematical model of the “standard observer,” which is an empirical mathematical relationship between color stimuli and color sensation (tristimulus values), and (2) a definition of the sRGB color space that specifies the reference illuminant and the mathematical transformation between tristimulus values and sRGB values.

The linear transformation relating a color stimulus, N, to its corresponding tristimulus values, Q, is

    \[Q_{3\mathsf{x}1} = A'_{3\mathsf{x}n}\;N_{n\mathsf{x}1}.\]

The column vector Q has three elements, X, Y, and Z. The matrix A' has three rows (called the three “color matching functions”) and n columns, where n is the number of discretized wavelength bands. In this study, all computations are performed with 36 wavelength bands of width 10 nm, running over the range 380 nm to 730 nm. The stimulus vector also has n components, representing the total power of all wavelengths within each band. The specific color matching functions I use in this work are the CIE 1931 color matching functions. (Note that I’m using the symbol A' here; the standard A matrix is n x 3, and so A' indicates that it has been transposed.)

The tristimulus vector, Q, can be constructed as the product of an n\mathsf{x}n diagonal illuminant matrix, \mathsf{diag}(W), and an n\mathsf{x}1 reflectance vector, \rho. The computation of Q is usually normalized so the Y tristimulus value is equal to 1 when \rho is a perfect reflector (contains all 1s). The normalizing factor, w, is thus the inner product of the second row of A' and the illuminant vector, W, yielding the alternate form of the tristimulus value equation

    \[Q = A'\;\mathsf{diag}(W)\;\rho/w.\]

See this page for more info on the above relationship.

The transformation from tristimulus values to sRGB is a two-step process. First, a 3\mathsf{x}3 linear transformation, M^{-1}, is applied to convert Q to rgb, which is a triplet of “linear RGB” values:

    \[rgb = M^{-1}\;A'\;\mathsf{diag}(W)\;\rho/w.\]

The second step is to apply a “gamma correction” to the linear rgb values, also known as “companding” or applying the “color component transfer function.” This is how it is done: for each r, g, and b component of rgb, let’s generically call it v, if v \le 0.0031308, use 12.92 v, otherwise use 1.055 v^{1/2.4}-0.055. This gives sRGB values in the range of 0 to 1. To convert them to the alternate integer range of 0 to 255 (used in most 24-bit color devices), we multiply each by 255 and round to the nearest integer.

sRGB to rgb
The inverse operation of converting sRGB to rgb, expressed in code, is:
sRGB=sRGB/255; % convert 0-255 range to 0-1 range
for i=1:3
  if sRGB(i)<0.04045
    rgb(i)=sRGB(i)/12.92;
  else
    rgb(i)=((sRGB(i)+0.055)/1.055)^2.4;
  end
end


The expression relating rgb and \rho above can be simplified by combining the three matrices and the normalizing factor into a single matrix, T=M^{-1}\;A'\;\mathsf{diag}(W)/w so that

    \[rgb = T\;\rho.\]

The formal definition of the sRGB color space uses an illuminant similar to daylight, called D65, as its “reference” illuminant. Here are the specific values for the M^{-1} matrix, the A' matrix, the D65 W vector, and the T matrix. The normalizing factor, w, has a value of 10.5677. Most of the RGB-related theory I present here I learned from Bruce Lindbloom’s highly informative website.

Now that we have a simple expression for computing sRGB from a reflectance curve, we can use that as the basis of doing the opposite, computing a reflectance curve from an sRGB triplet. In the sections that follow, I will present five different algorithms for doing this. Each has its strengths and weaknesses. Once they are presented, I will then compare them to each other and to reflectance curves found in nature.


Navigation

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 (this page)
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

← Previous Page Next Page →