% convertRGB.m - obsolete - see rgb2lms.m % % Takes a vector of RGB numbers and calculates CIE XYZ and Yxy coordinates, % as well as approximate LMS and MacLeod-Boynton Yrb coordinates. % % RGB numbers must be in the range 0->255. % *** Requires a linearized (gamma corrected) monitor. Results are grossly inaccurate without it. *** % % Uses Sony Trinitron XYZ coodinates from a Sony monitor driver color profile (www.sony.com). % % Assumes: % - no color temperature adjustments by video card or monitor % - no color management by application used to display RGB image % - accurate phosphor chromaticity coordinates % - no interaction between phosphors % Conversion to LMS and Yrb uses estimates of chromaticity coordinates of cone primaries by % Smith & Pokorny (1975) (accurate?), and arbitrary normalization so that L+M is luminance and S/(L+M) % is equal 1.0 for a 400nm spectral stimulus. See Y. Nakano's color vision math tutorial % in Kaiser & Boynton's COLOR VISION. % % maximum luminance is at Y = 1 % equal-energy white ends up at LMS = Y * [0.6654 0.3346 0.0161], % or rb = [0.6654 0.0161] % % 1/6/2001 rdb Wrote it. % 12/14/2001 rdb Changed yourXYZ calculation to simple weighting of phosphor XYZ coordinates % Corrected error in Yrb calculation b=S/(L+M), not M/(L+M) % maxRGB = 255; yourRGB=input('Enter an RGB vector, e.g. [255 128 128]: '); yourRGB = yourRGB./maxRGB; % Sony Trinitron phosphor XYZ coordinates rXYZ = [0.390503 0.209930 0.012619]; gXYZ = [0.31950 0.676605 0.078995]; bXYZ = [0.254196 0.113449 0.733276]; % whitepoint wXYZ = rXYZ + gXYZ + bXYZ; wYxy = [wXYZ(2) wXYZ(1)./(wXYZ(1)+wXYZ(2)+wXYZ(3)) wXYZ(2)./(wXYZ(1)+wXYZ(2)+wXYZ(3))] % phosphor chromaticity coordinates xr = rXYZ(1) ./ (rXYZ(1) + rXYZ(2) + rXYZ(3)); yr = rXYZ(2) ./ (rXYZ(1) + rXYZ(2) + rXYZ(3)); zr = rXYZ(3) ./ (rXYZ(1) + rXYZ(2) + rXYZ(3)); xg = gXYZ(1) ./ (gXYZ(1) + gXYZ(2) + gXYZ(3)); yg = gXYZ(2) ./ (gXYZ(1) + gXYZ(2) + gXYZ(3)); zg = gXYZ(3) ./ (gXYZ(1) + gXYZ(2) + gXYZ(3)); xb = bXYZ(1) ./ (bXYZ(1) + bXYZ(2) + bXYZ(3)); yb = bXYZ(2) ./ (bXYZ(1) + bXYZ(2) + bXYZ(3)); zb = bXYZ(3) ./ (bXYZ(1) + bXYZ(2) + bXYZ(3)); % from Kaiser & Boynton: RGBXYZ = [[xr./yr xg./yg xb./yb] % phosphor coordinate (RGB) to XYZ conversion matrix [1 1 1 ] [zr./yr zg./yg zb./yb]]; k = [[0.2535 0 0 ] % arbitrary scaling [0 -0.4000 0 ] [0 0 0.01327]]; SP75 = [[0.7465 1.4000 0.1748] % Smith and Pokorny (1975) copunctual points for dichromats [0.2535 -0.4000 0.0000] [0.0000 0.0000 0.8252]]; XYZLMS = k * inv(SP75); % XYZ to LMS conversion matrix % using Sony Trinitron phosphor coordinates: yourXYZ = RGB(1).* rXYZ + RGB(2).* gXYZ + RGB(3).* bXYZ; % conversions XYZ = yourXYZ; Yxy = [XYZ(2) XYZ(1)./(XYZ(1)+XYZ(2)+XYZ(3)) XYZ(2)./(XYZ(1)+XYZ(2)+XYZ(3))] LMS = XYZLMS * XYZ Yrb = [LMS(1)+LMS(2) LMS(1)./(LMS(1)+LMS(2)) LMS(3)./(LMS(1)+LMS(2))]