Page 74 - Computational Colour Science Using MATLAB
P. 74
IMPLEMENTATIONS AND EXAMPLES 61
lab(2) = 500*(fx(1)-fx(2));
lab(3) = 200*(fx(2)-fx(3));
To fully utilize the advantages of matrix algebra in MATLAB the function
xyz2lab could be written to accept a 36n matrix that would contain the
tristimulus values of n samples (where n is any positive integer) and would return
a36n matrix of CIELAB values. However, in this book the functions generally
have not been written in this way and if transformations are required for n
samples, then the functions must be called n times using a programming loop. It
is relatively straightforward to invert the CIELAB equations if the white point is
known. A function called lab2xyz has been provided for this purpose and has the
following typical function call:
[xyz] = lab2xyz(lab,’d65___64’);
where the variable lab is a 361 vector of CIELAB L*, a* and b* values.
Box 6: lab2xyz.m
function [xyz] = lab2xyz(lab,obs)
% function [xyz] = lab2xyz(lab,obs)
% computes XYZ tristimulus values from CIELAB LAB values
% requires the illuminant/observer obs to define white
% point
% see function r2xyz for valid values for obs
if strcmp(’a___64’,obs)
white=[111.144 100.00 35.200];
elseif strcmp(’a___31’, obs)
white=[109.074 100.00 35.585];
elseif strcmp(’c___64’, obs)
white=[97.285 100.00 116.145];
elseif strcmp(’c___31’, obs)
white=[98.074 100.00 118.232];
elseif strcmp(’d50___64’, obs)
white=[96.720 100.00 81.427];
elseif strcmp(’d___50’, obs)
white=[96.422 100.00 82.521];