File: uvYToXYZ.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 (42 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (7)
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
function XYZ = uvYToXYZ(uvY,compute1960)
% XYZ = uvYToXYZ(uvY,[compute1960])
%
% Compute tristimulus coordinates from chromaticity and luminance.
%
% These are u',v' chromaticity coordinates in notation
% used by CIE.  See CIE Colorimetry 2004 publication, or Wyszecki
% and Stiles, 2cd, page 165.
%
% Note that there is an obsolete u,v chromaticity diagram that is similar
% but uses 6 in the numerator for u rather than the 9 that is used for u'.
% See CIE Coloimetry 2004, Appendix A, or Judd and Wyszecki, p. 296. If
% you want this (maybe to compute correlated color temperatures), you can
% pass this as 1.  It is 0 by default.
%
% See also XYZTouvY, xyTouv, XYZToxyY, xyYToXYZ
%
% 10/31/94	dhb  Wrote it.
% 5/06/11   dhb  Improve comment.

%% Handle optional arg
if (nargin < 2 || isempty(compute1960))
    compute1960 = 0;
end

%% To handle 1960 input, take advantage of
% fact that all we need to do is scale v
% to get v'.  Then everything else flows
% as if we had passed u',v'.
if (compute1960)
    uvY(2,:) = uvY(2,:)*(9/6);
end

%% Do the computation
[m,n] = size(uvY);
XYZ = zeros(m,n);
for i = 1:n
  XYZ(1,i) = (9/4)*uvY(3,i)*uvY(1,i)/uvY(2,i);
  XYZ(2,i) = uvY(3,i);
  denom = 9*uvY(3,i)/uvY(2,i);
  XYZ(3,i) = (denom - XYZ(1,i)-15*XYZ(2,i))/3;
end