Skip to main content

NM and RGB

Wavelength → Red, Green, Blue

This algorithm is hugely perceptual and is not intended to be utilized for any scientific or measurement purposes. The purpose of xx is to give the spectrum a visual falloff as the wavelength approches 380 and 800, such that, at a bit depth of 8, 380nm ≈ [8,0,8] and 800nm ≈ [16,0,0]. RGB values will sometimes fall out of [0,1] and should be clamped.

γ=0.8R={λ440440380380λ<440λ510580510510λ<5801580λ8000 otherwise G={λ440490440440λ<4901490λ<580λ645645580580λ<6450 otherwise B={1360λ<490λ510510490490λ<5100 otherwise x={171+110(λ380)420380380λ<40015+57(λ400)420400400λ<4201420λ<70113+57(780λ)780700701λ<781132+15(800λ)800781781λ8000 otherwise f(y)=yxγ(R,G,B)=(f(R),f(G),f(B))\begin{align*} \gamma &= 0.8 \\ \:\\ R' &= \begin{cases} -\frac{\lambda - 440}{440 - 380} & 380 \leq \lambda < 440 \\ \frac{\lambda - 510}{580 - 510} & 510 \leq \lambda < 580 \\ 1 & 580 \leq \lambda \leq 800 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ G' &= \begin{cases} \frac{\lambda - 440}{490 - 440} & 440 \leq \lambda < 490 \\ 1 & 490 \leq \lambda < 580 \\ -\frac{\lambda - 645}{645 - 580} & 580 \leq \lambda < 645 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ B' &= \begin{cases} 1 & 360 \leq \lambda < 490 \\ \frac{\lambda - 510}{510 - 490} & 490 \leq \lambda < 510 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ x &= \begin{cases} \frac{1}{71} + \frac{\frac{1}{10} (\lambda - 380)}{420 - 380} & 380 \leq \lambda < 400 \\ \frac{1}{5} + \frac{\frac{5}{7} (\lambda - 400)}{420 - 400} & 400 \leq \lambda < 420 \\ 1 & 420 \leq \lambda < 701 \\ \frac{1}{3} + \frac{\frac{5}{7} \cdot (780 - \lambda)}{780 - 700} & 701 \leq \lambda < 781 \\ \frac{1}{32} + \frac{\frac{1}{5} (800 - \lambda)}{800 - 781} & 781 \leq \lambda \leq 800 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ f(y) &= yx^\gamma \\ \:\\ (R,G,B) &= (f(R'),f(G'),f(B')) \end{align*}