Page 51 - Computational Colour Science Using MATLAB
P. 51

38              COMPUTING CIE TRISTIMULUS VALUES



                 dim = size(P);
                 if (dim(1) == 1) | (dim(2) == 1)
                   P = P(:)’; % force to be a row matrix
                 else
                   disp(’P must be a row matrix’);
                   return;
                 end

                 a = 0.083;
                 n = length(P);
                 for i=2:n-1
                   cP(i) = -a*P(i-1) + (1 + 2*a)*P(i) - a*P(i+1);
                 end
                 cP(1) = (1 + a)*P(1) - a*P(2);
                 cP(n) = (1 + a)*P(n) - a*P(n-1);






                 The format for this function is


                    [cp] = cband(p)
               where p is an n61or16n matrix. In cband the dimensions of p are checked to
               ensure that only a single reflectance spectrum has been passed to the function.
               The p matrix is then converted to a row matrix. The MATLAB command

                    p = p(:)

               converts the matrix p into a column matrix and the transpose function is
               added

                    p = p(:)’

               to ensure that p is a row matrix.
                 This function operates on a single reflectance spectrum although it would be
               relatively easy to modify the code so that it operates on an n6m matrix of m
               reflectance spectra. The main purpose of this book is education rather than
               producing the fastest and most efficient code, and therefore most of the functions
               have been written to clearly demonstrate the computations involved. The following
               modification of cband, however, demonstrates how the code would be changed to
               allow more than one reflectance spectrum to be passed to the function:
   46   47   48   49   50   51   52   53   54   55   56