#### 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, , to its corresponding tristimulus values, , is

The column vector has three elements, , , and . The matrix has three rows (called the three “color matching functions”) and columns, where 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 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 here; the standard matrix is x 3, and so indicates that it has been transposed.)

The stimulus vector can be constructed as the product of an diagonal illuminant matrix, , and an reflectance vector, . The computation of is usually normalized so the tristimulus value is equal to 1 when is a perfect reflector (contains all 1s). The normalizing factor, , is thus the inner product of the second row of and the illuminant vector, , yielding the alternate form of the tristimulus value equation

The transformation from tristimulus values to sRGB is a two-step process. First, a 33 linear transformation, , is applied to convert to , which is a triplet of “linear RGB” values:

The second step is to apply a “gamma correction” to the linear values, also known as “companding” or applying the “color component transfer function.” This is how it is done: for each , , and component of , let’s generically call it , if , use , otherwise use . 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**

`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 and above can be simplified by combining the three matrices and the normalizing factor into a single matrix, so that

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 matrix, the matrix, the D65 vector, and the matrix. The normalizing factor, , 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