from
functions for computing relative luminance in W3C standard
by Alessandro Farini
two functions computing relative luminance and contrast ratio using the WCAG 2.0
|
| relativeluminance(erre,gi,bi) |
function relativeluminance = relativeluminance(erre,gi,bi)
% The function compute the relative luminance calculate using the Web
% Content Accessibility Guidelines (WCAG) 2.0.
% Relative Luminance isthe relative brightness of any point in a colorspace,
% normalized to 0 for darkest black and 1 for lightest white
% For the sRGB colorspace, the relative luminance of a color is defined
% as L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:
% if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4
% if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4
% if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4
% RsRGB, GsRGB, and BsRGB are defined as:
% RsRGB = R8bit/255
% GsRGB = G8bit/255
% BsRGB = B8bit/255
% Input are the three value of R,G,B expressed as a number between 0 and
% 255
% By Alessandro Farini 11 August 2009
%compute RsRGB as a value between 0 and 1
rsErre=erre/255;
rsGi=gi/255;
rsBi=bi/255;
%compute the value of RGB in sRGB space
if (rsErre>0.03928)
erreFinal=((rsErre+0.055)/1.055)^2.4;
else
erreFinal=rsErre/12.92;
end
if (rsGi>0.03928)
giFinal=((rsGi+0.055)/1.055)^2.4;
else
giFinal=rsGi/12.92;
end
if (rsBi>0.03928)
biFinal=((rsBi+0.055)/1.055)^2.4;
else
biFinal=rsBi/12.92;
end
%compute the relative luminance
relativeluminance = 0.2126*erreFinal + 0.7152*giFinal + 0.0722*biFinal;
|
|
Contact us at files@mathworks.com