Page 134 - Computational Colour Science Using MATLAB
P. 134
IMPLEMENTATIONS AND EXAMPLES 121
% obtained by dividing the RGB values by 255
% rgbs is an n by 1 matrix that is obtained from a linear
% transform of measured XYZ values
gamma = gogs(1);
gain = gogs(2);
% force to be row matrices
dacs = dacs(:)’;
rgbs = rgbs(:)’;
if (length(dacs) *= length(rgbs))
disp(’dacs and rgbs vectors must be the same length’);
err = 0;
return
end
% compute gog model predictions
for i = 1:length(dacs)
if (gain*dacs(i) + (1-gain)) 5=0
pred(i) = 0;
else
pred(i) = (gain*dacs(i) + (1-gain))^gamma;
end
end
% force to be a row matrix
pred = pred(:)’;
% compute rms error
err = sqrt((sum((rgbs-pred).*(rgbs-pred)))/...
length(dacs));
The MATLAB function fminsearch performs a multidimensional uncon-
strained non-linear minimization. Once the parameters have been determined,
the function compgog can be used to implement the GOG model. The format of
the call to compgog is
[rgb] = compgog(gogs,dacs)
where the returned n61 matrix rgb contains linearized R, G or B values for the n
samples defined by dacs.