Hue to wavelength mapping

Viewed 12611

Is there an algorithm to find out the wavelength of the color given the hue value (between 0 degree to 360 degree). Is there any built-in function in MATLABfor the same?

6 Answers

It is possible to find the dominant wavelength of a color/hue. But as said most colors arn’t monochromatic and the same color can be constructed with different “mixes” of wavelengths. I.e. metamerism. Also, for the extra spectral magenta and violet colors only a complementary wavelength can be specified. I.e. the hue/dominant wavelength that additively mixes to white. Also white must be specified, since the is no absolute white due to adaption. Also psychologically our perception of hues doesn’t follow dominant hue lines. Se the Munsell and NCS systems.

Here you can calulate dominant wavelength from RGB values or different CIE systems: http://www.brucelindbloom.com/index.html?Calc.html I don’t have the formula though.

You can then transform RGB to/from HSL and similar. And to/from Munsell or NCS perceptual hues (NCS values are proprietary, so you have to pay and use their software).

I found this site that converts a given wavelength to a hue. With a bit of work, you could actually reverse the process. It's not ideal, but I trust the guy who is a consultant in applied mathematics more than myself in solving this issue. That's that.

https://www.johndcook.com/wavelength_to_RGB.html

function convert(input) {
    var w = parseFloat(input);

    if (w >= 380 && w < 440) {
        r = -(w - 440) / (440 - 380);
        g = 0.0;
        b = 1.0;
    } else if (w >= 440 && w < 490) {
        r = 0.0;
        g = (w - 440) / (490 - 440);
        b = 1.0;
    } else if (w >= 490 && w < 510) {
        r = 0.0;
        g = 1.0;
        b = -(w - 510) / (510 - 490);
    } else if (w >= 510 && w < 580) {
        r = (w - 510) / (580 - 510);
        g = 1.0;
        b = 0.0;
    } else if (w >= 580 && w < 645) {
        r = 1.0;
        g = -(w - 645) / (645 - 580);
        b = 0.0;
    } else if (w >= 645 && w < 781) {
        r = 1.0;
        g = 0.0;
        b = 0.0;
    } else {
        r = 0.0;
        g = 0.0;
        b = 0.0;
    }


    // Let the intensity fall off near the vision limits
    if (w >= 380 && w < 420)
        factor = 0.3 + 0.7 * (w - 380) / (420 - 380);
    else if (w >= 420 && w < 701)
        factor = 1.0;
    else if (w >= 701 && w < 781)
        factor = 0.3 + 0.7 * (780 - w) / (780 - 700);
    else
        factor = 0.0;

    var gamma = 0.80;
    var R = (r > 0 ? 255 * Math.pow(r * factor, gamma) : 0);
    var G = (g > 0 ? 255 * Math.pow(g * factor, gamma) : 0);
    var B = (b > 0 ? 255 * Math.pow(b * factor, gamma) : 0);

    return [R, G, B]
}

There's no conversion because they don't overlap.

Hue moves you around an RGB colour space, usually sRGB that almost all consumer digital equipment uses. That's a subset of the colours that our visual systems recognise under normal conditions (defined by CIE 1931), and does not overlap the vibrant line of colours perceived at monochromatic wavelengths of light at all.

Though Hue from 0-120 (reddish orange to yellowish green) and near 240 (indigo) are reasonably close, sRGB is quite functional if you don't care about all the washed out greens and blues, and you can fake the violet and red ends of the full spectrum by making them darker Hue around 270 or 330 respectively, and the only place you can't really approximate is around 180, computer cyan just isn't close at all to the monochromatic vibrant blue-greens.

Related