Code covered by the BSD License  

Highlights from
functions for computing relative luminance in W3C standard

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.77 KB File ID: #24995

functions for computing relative luminance in W3C standard

by Alessandro Farini

 

11 Aug 2009

two functions computing relative luminance and contrast ratio using the WCAG 2.0

| Watch this File

File Information
Description

Relative Luminance is the 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

Contrast Ratio= (L1 + 0.05) / (L2 + 0.05), where
L1 is the relative luminance of the lighter of the colors, and
L2 is the relative luminance of the darker of the colors.
Note Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1). the input is the rgb value (from 0 to 255) of the ligheter and the darker colors.
The WCAG guidelines indicate that contrast ratio should be at least 4.5:1

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
vision Alessandro Farini 11 Aug 2009 11:45:17
webdesign Alessandro Farini 11 Aug 2009 11:45:17

Contact us at files@mathworks.com