color-luminance
v2.1.0
Published
bare-bones color luminance functions
Downloads
6,297
Maintainers
Readme
color-luminance
Functions for calculating the relative luminance of a RGB color. Since this is just a weighted sum, you can pass components in the range 0-255 or 0-1.
var luminance = require('color-luminance');
//example for RGB inputs in the range 0-255
var Y = luminance(255, 25, 125);
//or with RGB arrays
var Y = luminance([ 255, 25, 125 ]);
coefficients
The exported function uses the Rec. 601 standard for coefficients (used in most digital video formats).
More details here.
You can instead use the more explicit functions like so, depending on your needs:
var luminance = require('color-luminance');
//Uses Rec. 709 (HDTV) coefficients
//R * 0.2126 + G * 0.7152 + B * 0.0722
var y1 = luminance.rec709(r, g, b);
//Uses Rec. 601 (PAL/NTSC) coefficients
//R * 0.299 + G * 0.587 + B * 0.114
var y2 = luminance.rec601(r, g, b);
license
BSD-3-Clause