File: GenerateCIEDay.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (57 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [spd,xd,yd,M1,M2] = GenerateCIEDay(Temp,B)
% [spd,xd,yd] = GenerateCIEDay(Temp,[B])
% 
% Generate CIE daylights of the desired correlated color
% temperature.  Formulae are from W+S, pp. 145-146.
%
% The required basis vectors may be obtained by loading
% the file B_cieday.
%
% INPUT
%   Temp - row vector of color temperatures.  These should be
%       in the range 4000 - 25000.
%   B - CIE daylight basis vectors.
% 
% OUTPUT
%   spd - desired spectral power distributions
%   xd  - row vector of x chromaticities
%   yd  - row vector of y chromaticities
%
% 9/28/93   dhb, jms  Changed argument name to Temp
%                     If B not passed, return spd = [] and other data

% Get sizes
[null,m] = size(Temp);
xd = zeros(1,m);
yd = zeros(1,m);

% Compute xd chromaticities
index = find(Temp < 7000);
if (length(index) > 0)
  xd(index) = -4.6070*1e9./(Temp(index).^3) + 2.9678*1e6./(Temp(index).^2) ...
              + 0.09911*1e3./(Temp(index)) + 0.244063;
end
index = find(Temp >= 7000);
if (length(index) > 0)
  xd(index) = -2.0064*1e9./(Temp(index).^3) + 1.9018*1e6./(Temp(index).^2) ...
               + 0.24748*1e3./(Temp(index)) + 0.237040;
end

% Compute yd chromaticities
yd = -3.*(xd.^2) + 2.870.*xd - 0.275;

% Compute M0, M1 and M2
M0 = ones(1,m);
M1 = (-1.3515 - 1.7703.*xd + 5.9114.*yd) ./ ...
     (0.0241 + 0.2562.*xd - 0.7341 .* yd);
M2 = (0.03 - 31.4424.*xd + 30.0717.*yd) ./ ...
     (0.0241 + 0.2562.*xd - 0.7341 .* yd);

% Compute the SPD
M = [M0 ; M1 ; M2];
if (nargin == 2)
  spd = B*M;
else
  spd = [];
end