What's new

Math Help Needed!

kavadude

❦ॐ tanuki tamer
There's also a calculator on there. Is that not enough? Do you need to convert a bunch of stuff at once?
 

Steve Mariotti

Kavapithecus Krunkarensis
Review Maestro
Not my field, but looking at the equations, they're series that have to be computed for each coordinate, so that's a for-loop that can be done inside Excel with a little script, I think.

This paper looks interesting:

http://www.ppsloan.org/publications/XYZJCGT.pdf

They provide sample C code for X, Y and Z computation based on someting similar to the emissive conversion function on that page, by my eye. It is a "multi-lobe gaussian fit" as described below:

Our best fits use multiple piecewise continuous Gaussians for each curve. With three Gaussians for ˜x and two for ˜y and ˜z, we achieved squared error rates below the within-observer variance in the experimental measurements used to form the CIE standards [Nimeroff et al. 1962]. While adding additional Gaussians could reduce numerical error, we would effectively be fitting noise in the data; more error is likely added elsewhere, e.g., during monitor and printer color calibration.
// Inputs: Wavelength in nanometers
float xFit_1931( float wave )
{
float t1 = (wave-442.0f)*((wave<442.0f)?0.0624f:0.0374f);
float t2 = (wave-599.8f)*((wave<599.8f)?0.0264f:0.0323f);
float t3 = (wave-501.1f)*((wave<501.1f)?0.0490f:0.0382f);

return 0.362f*expf(-0.5f*t1*t1) + 1.056f*expf(-0.5f*t2*t2) - 0.065f*expf(-0.5f*t3*t3);
}

float yFit_1931( float wave )
{
float t1 = (wave-568.8f)*((wave<568.8f)?0.0213f:0.0247f);
float t2 = (wave-530.9f)*((wave<530.9f)?0.0613f:0.0322f);
return 0.821f*exp(-0.5f*t1*t1) + 0.286f*expf(-0.5f*t2*t2);
}

float zFit_1931( float wave )
{
float t1 = (wave-437.0f)*((wave<437.0f)?0.0845f:0.0278f);
float t2 = (wave-459.0f)*((wave<459.0f)?0.0385f:0.0725f);
return 1.217f*exp(-0.5f*t1*t1) + 0.681f*expf(-0.5f*t2*t2);
}


This paper discusses techniques used in computer video cards for fast colorspace conversion, and may lack the precision you'd want for lab purposes. First thing I'd do replace all the "float" floating point numbers (single precision, 32 bit values) with "double" floating point numbers, (64 bit values). Then I'd recompute their constants (or look them up) and find higher precision values.

There may be a better reference than this, but I was looking for some code that could be implemented easily in Excel.
 

verticity

I'm interested in things
@Deleted User, Excel may not be the best too for that problem. You can make Excel do just about anything, but it probably won't be pretty.

I would suggest using an existing code library that implements these equations, such as this one:
http://www.codeproject.com/Articles/613798/Colorspaces-and-Conversions
This is open source code that anyone can download and use in projects. It uses Microsoft's C# language which I am very familiar with. I can help write a front end using this library I think (after I do some studying to better understand color theory)
 

Steve Mariotti

Kavapithecus Krunkarensis
Review Maestro
I've started coding it in C++.

Though there's another python library that looks good too: http://colour-science.org/

Unfortunately, that linked C function of yours implements spectral analysis for black body radiation, which I believe is emissive. We want the reflective calculations that use a slightly more complicated form of the equations. That include a reference illuminant in addition to the color matching functions for each x, y, z component.

ColorPy may do it, but the equations they list are for emissive.

X = ∫ I (λ) * CIE-X (λ) * dλ
Y = ∫ I (λ) * CIE-Y (λ) * dλ
Z = ∫ I (λ) * CIE-Z (λ) * dλ

I located the CIE color matching functions (CIE 1931) for 2-degree observer angle (the common one, apparently) and the data for the D65 reference illuminant (also the common one, I think) so now it's a matter of interpolating between the spectrometer wavelenths and the wavelengths represented in the CMF's and the reference illuminant and summning all that shit up.

On Bruce Lindblooms site, the equations look more like:



Which turns into the sum of, for all lambdas in the spectral data from the machine: the color matching function at wavelength lambda * the spectral data (transmission) at wavelength lambda * the reference illuminant at wavelength lambda.

And then each component normalized by N.

At least that's what I currently think it is. I just started looking at this stuff the other night, and I have no experience in color science. If anyone sees any issues with what I said in this message, please let me know!
 

verticity

I'm interested in things
I've started coding it in C++.

Though there's another python library that looks good too: http://colour-science.org/

Unfortunately, that linked C function of yours implements spectral analysis for black body radiation, which I believe is emissive. We want the reflective calculations that use a slightly more complicated form of the equations. That include a reference illuminant in addition to the color matching functions for each x, y, z component.

ColorPy may do it, but the equations they list are for emissive.
The C program includes a test program that calculates X, Y, Z of black body radiation at various temperatures, but it includes the function
spectrum_to_xyz which could be used to calculate X, Y, Z for an arbitrary spectrum.

We do not want the formulas for reflectance, because Deleted User is not doing reflectance spectroscopy. He is shining a light through the sample, and measuring how much is transmitted through. This is basically equivalent to measuring what is emitted from the sample, if you neglect the light source. No light is being reflected, it is just passing through the sample.

C++ ... So can you pronounce Bjarne Stroustrup correctly? lol
 

kavadude

❦ॐ tanuki tamer
Fun fact, I almost went to Texas A&M and would've been taking classes with Stroustrup. Good thing I didn't because screw pronouncing his name.
 
D

Deleted User01

You might search the internet for a calculator program that does that. The database language that I use doesn't support integrals just basic arithmetic. @Steve Mariotti, for this kind of project, it would be nice to have a few good examples with the answers so you could test the formulas. Geez, I didn't no there were so many rocket scientists on this ship. I have a degree in math but it was 40 years ago and I don't remember any of it since I never used it. Just accounting programming.
 

verticity

I'm interested in things
You might search the internet for a calculator program that does that. The database language that I use doesn't support integrals just basic arithmetic. @Steve Mariotti, for this kind of project, it would be nice to have a few good examples with the answers so you could test the formulas. Geez, I didn't no there were so many rocket scientists on this ship. I have a degree in math but it was 40 years ago and I don't remember any of it since I never used it. Just accounting programming.
You don't need integration, just summation. It would be fun to implement it in SQL.. fun for someone other than me, that is..
 
D

Deleted User01

@Deleted User, try CNET if see if they have an freeware you can use. Summation might work but it's hard to find time for a side project. There's gotta be something already made out there. I trying to remember this fancy software called Mathematica which did tons of formulas. There must be some "freeware" out there.
 
Top