Page 118 - Computational Colour Science Using MATLAB
P. 118
IMPLEMENTATIONS AND EXAMPLES 105
% implements the CIECAM97s colour appearance model
% operates on 1 by 3 matrix xyz containing tristimulus
% values of the stimulus under the test illuminant
% xyzt and xyzr are 1 by 3 matrices containing the
% white points for the test and reference conditions
% la and yb are the luminance and Y tristimulus values of
% the achromatic background against which the sample is
% viewed
% para is a 1 by 4 matrix containing c, Nc, Fll and F
c = para(1); nc = para(2);
fll = para(3); f = para(4);
MH = [0.38971 0.68898 -0.07868; -0.22981 1.18340 0.04641;
0.0 0.0 1.0];
MBFD = [0.8951 0.2664 -0.1614; -0.7502 1.7135 0.0367;
0.0389 -0.0685 1.0296];
% white in reference light
x = 0.3333; y = 0.3333; Y = 100.00;
xyzwr(1) = x*Y/y; xyzwr(2) = Y; xyzwr(3) = (1-x-y)*Y/y;
xyzwr = xyzwr’;
% step 1
rgb = MBFD*(xyz/xyz(2));
rgbw = MBFD*(xyzw/xyzw(2));
rgbwr = MBFD*(xyzwr/xyzwr(2));
% step 2
d = f - f/(1 + 2*(la^0.25) + (la^2)/300);
p = (rgbw(3)/rgbwr(3))^0.0834;
rgbc(1) = (d*(rgbwr(1)/rgbw(1)) + 1 - d)*rgb(1);
rgbc(2) = (d*(rgbwr(2)/rgbw(2)) + 1 - d)*rgb(2);
rgbc(3) = (d*(rgbwr(3)/(rgbw(3)^p)) + 1 - d)*
abs(rgb(3))^p; if (rgb(3) 50)
rgbc(3) = -rgbc(3);
end
rgbwc(1) = (d*(rgbwr(1)/rgbw(1)) + 1 - d)*rgbw(1);
rgbwc(2) = (d*(rgbwr(2)/rgbw(2)) + 1 - d)*rgbw(2);
rgbwc(3) = (d*(rgbwr(3)/(rgbw(3)^p)) + 1 - d)* . . .
abs(rgbw(3))^p; if (rgbw(3)50)
rgbwc(3) = -rgbwc(3);