Page 111 - Computational Colour Science Using MATLAB
P. 111

98 CHROMATIC-ADAPTATION TRANSFORMS AND COLOUR APPEARANCE



                 % implement step 1: normalise xyz and transform to rgb
                 rgb = M*(xyz/xyz(2));
                 rgbt = M*(xyzt/xyzt(2));
                 rgbr = M*(xyzr/xyzr(2));

                 % implement step 2: compute d, the degree of adaptation
                 d = f - f/(1 + 2*(la^0.25) + la*la/300);
                 % clip d if it is outside the range [0,1]
                 if (d50)
                   d=0;
                 elseif (d41)
                   d=1;
                 end


                 p = (rgbt(3)/rgbr(3))^0.0834;

                 % implement step 3: compute corresponding rgb values
                 rgbc(1) = rgb(1)*(d*rgbr(1)/rgbt(1) + 1 - d);
                 rgbc(2) = rgb(2)*(d*rgbr(2)/rgbt(2) + 1 - d);
                 rgbc(3) = (d*(rgbr(3)/(rgbt(3)^p)) + 1 -
                 d)*abs(rgb(3))^p;
                 if (rgb(3) 5 0)
                   rgbc(3) = -rgbc(3);
                 end

                 % implement step 4: convert from rgb to xyz
                 xyzc = inv(M)*(rgbc’*xyz(2));



                 The default values of the parameters will be used if the following form of the
               function call is used:

                    [xyzc] = cmccat97(xyz, xyzt, xyzr).

               The function returns a 361 matrix xyzc containing the corresponding
               tristimulus value for the sample under the reference illuminant. The corre-
               sponding colour under illuminant D65 for a sample with tristimulus values of
               34.1827, 39.2556 and 14.8082 under illuminant A would be generated using the
               following MATLAB code,

                    xyz = [34.1827 39.2556 14.8082];
                    xyzt = [111.144 100.00 35.200];
   106   107   108   109   110   111   112   113   114   115   116