On the calculation of SRM RGB values in the sRGB color space

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

ShootsNRoots

Well-Known Member
Joined
Mar 27, 2013
Messages
243
Reaction score
34
Wrote a program that makes an SRM color chart in the sRGB color space.

I don't have access to ASTM E-308, but guesstimating what it says:

1.) The following gives a transmission spectrum that when integrated gives an XYZ value with a C-Illuminant and a 10 degree observer.

d84e66c2ba54919221264ea32b278a7a.png


2.) Chromatically adapt the value from the previous step to the native sRGB D-65 Illuminant using a Bradford adaptation matrix.

3.) Convert the value from the previous step to RGB using the sRGB D-65 Illuminant conversion matrix.

This produces a reasonable chart.

My question is for those that have access to ASTM E-308, what is the algorithm that it specifies?

Is there a better method?
 
Wrote a program that makes an SRM color chart in the sRGB color space.

I don't have access to ASTM E-308, but guesstimating what it says:

1.) The following gives a transmission spectrum that when integrated gives an XYZ value with a C-Illuminant and a 10 degree observer.

d84e66c2ba54919221264ea32b278a7a.png

That has nothing to do with ASTM E-308. This formula, as it appears in the Wikipedia article, is derived from a double exponential fit to the average of the normalized (to the absorption at 430 nm) spectra of 99 beers measured in an investigation of beer color. That ensemble included several fruit beers (lambics, krieks, blueberry wheat....) and so is representative of a large universe of beers but is redder than the average normalized spectrum of malt only beers. Un-normalizing by multiplying by the absorption of a beer with a given SRM at 430 nm (SRM/12.7) gives the absorption of a spectrally average beer in 1 cm. Taking the antilog of the negative of this gives the transmission of a spectrally average beer in 1 cm.

2.) Chromatically adapt the value from the previous step to the native sRGB D-65 Illuminant using a Bradford adaptation matrix.

The quality of the illuminant and color space don't come into it yet. The first thing you need to do is determine what path (thickness of beer) you are interested in and determine the transmission spectrum in that thickness. This is done by scaling the 1 cm absorption spectrum by the thickness in cm before taking the antilog. Thus if the path is 5 cm (typical beer glass width?) then you would multiply by 5 before taking the antilog. ASTM E-308 comes into play when you have the transmission spectrum of the thing whose color you wish to determine. The first step is to multiply the transmission spectrum by the power distribution spectrum of the particular illuminant you are interested in. That product is then point wise multiplied by samples from each of three color matching functions, one each for X,Y and Z, and the products summed (separately for X,Y and Z) and each sum is normalized by 100 divided by the dot product of the illuminant spectrum with the Y color matching function. These give values for the color in X, Y, Z, coordinates. This can be transformed into any space derived from X, Y, Z (such as L,a,b, R,G,B ...) by using the proper formulae.

3.) Convert the value from the previous step to RGB using the sRGB D-65 Illuminant conversion matrix.

In E-308 the illuminant is accounted for before the color matching functions are applied. One could, of course, pre-compute x, y and z vectors (CMF's) for each illuminant of interest. This is a little counter productive as the D family spectra are computed as a function of coordinated color temperature from three eigen functions and for maximum flexibility one usually does that. Of course if you are only interested in D65 you can pre-compute for D65. It is worthy of note that the ASBC in its tristimulus MOA (Beer 10 C) uses Illuminant C, a 1 cm path and the 10° observer (there are two sets of x, y and z CMF vectors depending on whether the beer subtends 2° or 10° at the viewer's eye.

The details of the calculation can be found in most color science books and are used in the spreadsheet at

http://wetnewf.org/pdfs/Brewing_articles/MOAWorkbook.xls

which contains the 2° and 10° color matching functions, the A, C and F illuminant spectra and the ability to compute the D illuminant spectra (all the numbers are on a third sheet as are the X,Y,Z; L,a,b; and R,G,B calculations). It's going to take a bit of figuring out (there are some instructions) but in essence you paste a beer's absorption spectrum (there are examples on a fourth sheet) into the first column and specify a path and illuminant in return for which it calculates 2° and 10° colors in L,a,b and R,G,B (based on the Rec. 709 primaries). It also calculates 'spectral deviation coefficients' which are measures of the degree to which a particular beers actual normalized spectrum differs from the average normalized spectrum. If you put an SRM value without specifying any SDC's (all entries in that column 0) the spreadsheet calculates the colors of the average beer with that SRM which is, I think, what you are actually after.



This produces a reasonable chart.
The problem that you will find is that the colors of beer in any reasonable path with any but very small SRMs are much more saturated (red) than any monitor, film or printing process can produce. The sRGB gamut is particularly limited.


My question is for those that have access to ASTM E-308, what is the algorithm that it specifies?
1. Choose an observer, 2° or 10°. Obtain the vectors x, y and z for that observer (these are in the spreadsheet).
2. Choose an illuminant and obtain (or compute) its spectrum: S.
3. Calculate the normalizing constant c = 100/<S,y> where <S,y> is the dot product of S and y.
4. Compute the transmission spectrum of the beer, t, from the average spectrum formula considering the path or from measurements of the actual beer.
5, Compute the light coming through the beer by multiplying, for each wavelength, S by t: t' = {S*t}
6. Compute
X = c*<t',x>
Y = c*<t',y>
Z = c*<t',z>
7. Transform to L,a,b (set all elements of t to 1 and compute Xw, Yw and Zw, the white point, first).
8. Transform to other color spaces.

Is there a better method?
Depends on what you are trying to do. If you are interested in color differences there are better spaces than L,a,b but L,a,b is generally considered good enough. If you want to compute CIE colors this is the only way as x,y and z define what these colors are.

If you want more information you'll have to go to a color text or search the internet. I've found the X,Y,Z to L,a,b formulas there and even the color matching functions (you need the set with 5 nm spacing). If you are interested in the particulars of the work that led to the transmission formula you quoted and the spreadsheet PM me and I'll send you a .pdf of the paper.
 
The first thing you need to do is determine what path (thickness of beer) you are interested in and determine the transmission spectrum in that thickness. This is done by scaling the 1 cm absorption spectrum by the thickness in cm before taking the antilog. Thus if the path is 5 cm (typical beer glass width?) then you would multiply by 5 before taking the antilog.

I'm missing this part.

ASTM E-308 comes into play when you have the transmission spectrum of the thing whose color you wish to determine. The first step is to multiply the transmission spectrum by the power distribution spectrum of the particular illuminant you are interested in. That product is then point wise multiplied by samples from each of three color matching functions, one each for X,Y and Z, and the products summed (separately for X,Y and Z) and each sum is normalized by 100 divided by the dot product of the illuminant spectrum with the Y color matching function. These give values for the color in X, Y, Z, coordinates. This can be transformed into any space derived from X, Y, Z (such as L,a,b, R,G,B ...) by using the proper formulae.

Already doing this. Didn't realize there was a document specifically related to solving an integral.

The problem that you will find is that the colors of beer in any reasonable path with any but very small SRMs are much more saturated (red) than any monitor, film or printing process can produce. The sRGB gamut is particularly limited.

My concern is that the highest lovibond/srm values produce RGB values with no green or blue in them. They are saturated with red. Is this correct? I don't believe this is a product of the sRGB space, of course I could try a massive RGB color space like ProPhoto or even Adobe RGB which would be slightly bigger than sRGB. Also, switching to a 10 degree observer, a C illuminant and increasing the path from 1cm might make a difference.
 
I'm missing this part.

I'm not sure what you mean here. If by 'missing' you mean that it isn't in the equation you posted then, yes, that's so. If you mean you don't understand that bit then look at the Bougert-Beer-Lambert Law

A = l*e*c

which says that the absorption in a passing through a thickness of beer of length l is proportional to the concentration of the colorant, c, and an extinction coefficient, c. Thus the absorption is a 1 cm path is 1*e*c and in a 2 cm path 2*e*c. The formula gives values for a 1 cm path. For a two cm path the absorption at each wavelength is twice the absorption given by the formula and so on and the transmission is, thus, 10^-2 = 1% if what it is for 1 cm as given by the formula.



Already doing this. Didn't realize there was a document specifically related to solving an integral.

I'm confused here too. You certainly don't need to solve any integrals here (for which you should be grateful!). You are simply evaluating a couple of dot products. Perhaps you are thinking of the dot product as an approximation to the evaluation of an integral. If you are already doing what I sketched here and detailed in the enumerated steps later then you are following E-308. That's what it directs you to do.



My concern is that the highest lovibond/srm values produce RGB values with no green or blue in them. They are saturated with red. Is this correct?

Yes. Look at the shape of an absorption spectrum and think about Beer-Lambert and the nature of logarithms. As the path increases to 5 cm, for example, in a 12.7 SRM beer the absorption at 430 nm is 1 (10% transmission) in a 1 cm path. At 700 nm it might be 0.05 (89% transmission). In a 5 cm path the absorption at 430 would be 5.0 (transmission 0.003%) while at 700 it would be 0.25 (56% transmission). The light coming through is very red. Beer colors are very restricted. In a chromaticity diagram as the SRM increases allowable beer colors describe a graceful curve which approaches the saturation line at the red end.


I don't believe this is a product of the sRGB space,
This has nothing to do with the space used to describe the color. It is a consequence of the nature of beer.


.. of course I could try a massive RGB color space like ProPhoto or even Adobe RGB which would be slightly bigger than sRGB.

Compared to x,y color space these are hardly 'massive'. They are bigger but not nearly big enough.

Also, switching to a 10 degree observer, a C illuminant and increasing the path from 1cm might make a difference.

The observer and the illuminant won't make much difference. The path is the big driver here. You can verify all these statements by playing around with that spreadsheet I mentioned in my last post.
 
I'm not sure what you mean here. If by 'missing' you mean that it isn't in the equation you posted then, yes, that's so.

Just meant I didn't write code to account for the path.

I'm confused here too. You certainly don't need to solve any integrals here (for which you should be grateful!). You are simply evaluating a couple of dot products. Perhaps you are thinking of the dot product as an approximation to the evaluation of an integral. If you are already doing what I sketched here and detailed in the enumerated steps later then you are following E-308. That's what it directs you to do.

You're right I'm evaluating the integral via summations (not solving it)...

Eqn_Spect_XYZ_3.gif


Eqn_Spect_XYZ_4.gif


Compared to x,y color space these are hardly 'massive'. They are bigger but not nearly big enough.

Well yea, but comparing x,y color space to RGB color space is apples/oranges... and I'm focusing on RGB.

The observer and the illuminant won't make much difference. The path is the big driver here.

Yup, have to get the code written to account for the path.

I'll see If I can't post my code and a chart (when back from vacation).
 
Yes. Look at the shape of an absorption spectrum and think about Beer-Lambert and the nature of logarithms. As the path increases to 5 cm, for example, in a 12.7 SRM beer the absorption at 430 nm is 1 (10% transmission) in a 1 cm path. At 700 nm it might be 0.05 (89% transmission). In a 5 cm path the absorption at 430 would be 5.0 (transmission 0.003%) while at 700 it would be 0.25 (56% transmission). The light coming through is very red. Beer colors are very restricted. In a chromaticity diagram as the SRM increases allowable beer colors describe a graceful curve which approaches the saturation line at the red end.

That makes sense. Thanks AJ.
 
You're right I'm evaluating the integral via summations (not solving it)...

Think I understand your question better now. E-308 is just a prescription, that is, a standardized method for estimating the values of those integrals using subsampled CMFs with the particular wavelengths (380 - 780 nm in 5 nm steps) to be used specified and values for the CMFs and illuminant densities at the wavelengths to be used specified. Follow it and you will, given that we are working with the same spectrum, get the same answer I do


Well yea, but comparing x,y color space to RGB color space is apples/oranges... and I'm focusing on RGB.

Understood but the CIE x,y,z space incorporates all colors, including spectrally pure (monochromatic, 100% saturated) colors. The 'D' flipped on its side curve in an x,y (chromaticity) diagram is the locus of pure spectral colors. Thus the x,y,Y specification is a great way to specify color because any color you can gin up additively 'fits' within it. It's not so great because the perceptible color difference between a pair of points depends a great deal on where in the 'D' the points fall: thus the L*,a*,b* and similar systems. L*,a*,b* is a 'connecting' space i.e. it is supposed to be device independent and that's why, for example, the ASBC tristimulus method uses that space, why Photo Shop does all its work in that space etc. It is only when we have to go to a physical device that we use R,G,B and those physical devices have limitations as to the range of colors they can provide. It is usual to compare different coordinate systems by plotting their envelopes on the x,y diagram, for example the following diagram shows that sRGB doesn't cover a lot of possible beer colors (they sort of follow the Planckian locus).

http://en.wikipedia.org/wiki/File:Cie_Chart_with_sRGB_gamut_by_spigget.png
 
Here's an SRM Chart generated with my program, when compared with the SRM charts found across the internet mine doesn't have the bright yellows and browns, it's more subdued to start and then gets more red/reddish brown.

I've used the following parameters:

-1 cm path
-Weight of grain (lbs) = Lovibond
-Volume = 1 gal.
-Lovibond = 1 - 40

Conversion to SRM by Morey equation.

srm.jpg


Same parameters except using a 5 cm path:

srm5.jpg
 
The linked chart shows the effects of path and SRM (color intensity) for Illuminant C and Rec. 790 RGB plus whatever unknown transformations are implied by posting the image to Pbase. SRM to transmission spectrum from relationship in #1 (or rather from the data from which the equation in #1 was derived).

http://www.pbase.com/agamid/image/118826578
 
Thanks AJ. After removing the Lovibond to SRM Conversion (Morey Equation) the charts more closely match the 1cm and 5cm slices of the chart you linked (of course mine are 2 Degree observer, D50 Illuminant and sRGB).

What I don't understand is how all of the beer software out there computes their final RGB color. They most certainly aren't doing anything near this complex. It seems they have a simple table of RGB values for which they look up and interpolate to obtain an RGB value after computing an SRM value from one of the Lovibond -> SRM conversion equations. This seems to give exaggerated hues.

1cm path:

srm1.jpg


5cm path:

srm5.jpg


10cm path:

srm10.jpg
 
I haven't specifically done SRM->RGB but I recently had to write some code that did some similar sorts of color modification. What I did was start with some known colors in the CIELab color space, and then lighten/darken them appropriately by just changing the L value and keeping a & b constant. This allows me to get a variety of shades of brown (for example) which appear lighter or darker by scaling appropriately depending upon my figure of merit. Then as the final step in rendering to the screen, I convert from CIELab color space to sRGB which as AJ already mentioned is a simple dot product operation.
 
The linked chart shows the effects of path and SRM (color intensity) for Illuminant C and Rec. 790 RGB plus whatever unknown transformations are implied by posting the image to Pbase. SRM to transmission spectrum from relationship in #1 (or rather from the data from which the equation in #1 was derived).

http://www.pbase.com/agamid/image/118826578

Can the author here provide a more layman's explanation on how to do this. Am I understand that x,y,z variables are required? Can you provide an example given x, y, z variables are provided?
 
Actually X, Y and Z are required or, equivalently x,y,Y. Remember that
x = X/(X + Y + Z), y = Y/(X + Y + Z) and z = Z/(X + Y + Z). If you have computed X, Y and Z using an illuminant that has a white point different from that of the RGB space you wish to transform to then you must also have Xn, Yn and Zn, the white point for that illuminant. From this you transform to L*a*b* using the transformation in http://en.wikipedia.org/wiki/Lab_color_space. Now use Xm, Ym, Zm, the white point of the RGB space you want to transform to to get new X, Y, and Z for the new white point using the inverse of the transform at http://en.wikipedia.org/wiki/Lab_color_space. Now transform the new X, Y and Z to R,G,B using the transformation for the RGB space you want at http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html. Be sure to use one of the inverse matrices.

I'm not sure if this is a "layman's" explanation. If you don't speak the basic language of color theory it would take pages to describe how to do this. See a color theory text.
 
Although I appreciate the time you put into writing this, I just don't have the educational background to be able to make any sense of this. I'll try, but it's way above my skill level.

What I'm trying to do is to do is get the RGB values given that the lovibonds, and path are known. I probably require more variables like light intensity. Maybe more. Does the spreadsheet that you provided in the first few posts accomplish this?
 
Having downloaded your sheet, I think I figured this out without really knowing any of the theory or math. Thanks for your help!
 
What I'm trying to do is to do is get the RGB values given that the lovibonds, and path are known. I probably require more variables like light intensity. Maybe more.
You have set yourself a very difficult task unless you are willing to be satisfied with a very approximate result. To begin with the Lovibond colors reported by maltsters are the colors of Congress laboratory worts made from the grains and not, therefore, more than approximately the colors of beers made from them using normal brewing procedures. Color development is directly proportional to the length of the boil. Using the same malts in a decoction program will result in deeper color than the same malts used in an infusion program (with the same length boil). In addition to that, fermentation changes the color of the wort.

Second, the Lovbond color system is based on visual comparison of wort color to a series of colored glass slides. It has been well known for years that the slides do not match actual wort colors and various suggestions have been made as to how to improve them but what the Tintometer Company actually puts into its visual comparison instruments and what mapping they use in their photometrically based instruments is known only to the Tintometer Company. When I requested information from them on this stating that I would be discussing the Lovibond Sytem in Bamforth's forthcoming book I was ignored.

The only people using the Lovibond system to describe malt colors are US maltsters. Everyone else uses EBC color and that, of course, has many of the shortcomings mentioned in the last paragraph but at least it is an instrumental measurement and beer spectra are, as discussed earlier in this thread, fairly well behaved. Given that you have the EBC color of a malt you can translate that trivially to absorption at 430 nm and produce the absorption spectrum (from the equation in the first post) attributable to that malt knowing the concentration of that malt in your mash relative to that in the Congress mash ignoring differences between your brewing procedure and the Congress procedure. The absorption spectrum of the beer would be assumed to be the sum of the absorption spectra of the original malt components.

Note that no malt will have a spectrum as given by the formula as this is the spectrum of an average beer with the ensemble including some Krieks, Framboises etc. There are ways to correct for this but you need more information than is given in just the EBC rating for a malt.

Does the spreadsheet that you provided in the first few posts accomplish this?

From the absorption spectrum of the beer estimated as discussed above one can calculate beer color in any of a variety of systems and this is what the spreadsheet does. It does not do any of the things required to calculate the beer spectrum.

Having downloaded your sheet, I think I figured this out without really knowing any of the theory or math. Thanks for your help!

That's great! You still have to figure out how to combine reported malt colors to get the spectrum of the beer but once you have that the path to RGB or LAB or LUV or whatever is in that spreadsheet.
 
Back
Top