1 | function J=xyz2luv(I,illuminant) |
---|
2 | % XYZ2LUV Convedrt XYZ to LUV |
---|
3 | % J = XYZ2LUV(I) converts the image I in XYZ format to the Luv format |
---|
4 | % (using by default the illuminant E). |
---|
5 | % |
---|
6 | % J = XYZ2LUV(I,illuminant) uses the specified illuminant. The following |
---|
7 | % illuminant are supported: A, B, C, E, D50, D55, D65, D75, D93. |
---|
8 | % |
---|
9 | % See also XYZ2LAB(). |
---|
10 | |
---|
11 | % AUTORIGHTS |
---|
12 | % Copyright (C) 2006 Andrea Vedaldi |
---|
13 | % |
---|
14 | % This file is part of VLUtil. |
---|
15 | % |
---|
16 | % VLUtil is free software; you can redistribute it and/or modify |
---|
17 | % it under the terms of the GNU General Public License as published by |
---|
18 | % the Free Software Foundation; either version 2, or (at your option) |
---|
19 | % any later version. |
---|
20 | % |
---|
21 | % This program is distributed in the hope that it will be useful, |
---|
22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | % GNU General Public License for more details. |
---|
25 | % |
---|
26 | % You should have received a copy of the GNU General Public License |
---|
27 | % along with this program; if not, write to the Free Software Foundation, |
---|
28 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
29 | |
---|
30 | if nargin < 2 |
---|
31 | illuminant='E' ; |
---|
32 | end |
---|
33 | |
---|
34 | switch illuminant |
---|
35 | case 'A' |
---|
36 | xw = 0.4476 ; |
---|
37 | yw = 0.4074 ; |
---|
38 | case 'B' |
---|
39 | xw = 0.3324 ; |
---|
40 | yw = 0.3474 ; |
---|
41 | case 'C' |
---|
42 | xw = 0.3101 ; |
---|
43 | yw = 0.3162 ; |
---|
44 | case 'E' |
---|
45 | xw = 1/3 ; |
---|
46 | yw = 1/3 ; |
---|
47 | case 'D50' |
---|
48 | xw = 0.3457 ; |
---|
49 | yw = 0.3585 ; |
---|
50 | case 'D55' |
---|
51 | xw = 0.3324 ; |
---|
52 | yw = 0.3474 ; |
---|
53 | case 'D65' |
---|
54 | xw = 0.312713 ; |
---|
55 | yw = 0.329016 ; |
---|
56 | case 'D75' |
---|
57 | xw = 0.299 ; |
---|
58 | yw = 0.3149 ; |
---|
59 | case 'D93' |
---|
60 | xw = 0.2848 ; |
---|
61 | yw = 0.2932 ; |
---|
62 | end |
---|
63 | |
---|
64 | J=zeros(size(I)) ; |
---|
65 | |
---|
66 | % Reference white |
---|
67 | xw = 1/3 ; |
---|
68 | yw = 1/3 ; |
---|
69 | Yw = 1.0 ; |
---|
70 | Xw = xw/yw ; |
---|
71 | Zw = (1-xw-yw)/yw * Yw ; |
---|
72 | |
---|
73 | J=zeros(size(I)) ; |
---|
74 | |
---|
75 | X = I(:,:,1) ; |
---|
76 | Y = I(:,:,2) ; |
---|
77 | Z = I(:,:,3) ; |
---|
78 | |
---|
79 | upw = 4*Xw / (Xw + 15*Yw + 3*Zw) ; |
---|
80 | vpw = 9*Yw / (Xw + 15*Yw + 3*Zw) ; |
---|
81 | |
---|
82 | up = 4*X ./ (X + 15*Y + 3*Z) ; |
---|
83 | vp = 9*Y ./ (X + 15*Y + 3*Z) ; |
---|
84 | |
---|
85 | sp = find( Y / Yw > 0.008856) ; |
---|
86 | sm = find( Y / Yw <= 0.008856) ; |
---|
87 | |
---|
88 | L = zeros(size(Y)) ; |
---|
89 | L(sp) = 116*( Y(sp) / Yw ).^(1/3) - 16 ; |
---|
90 | L(sm) = 903.3*( Y(sm) / Yw ) ; |
---|
91 | |
---|
92 | u = 13 * L .* (up - upw) ; |
---|
93 | v = 13 * L .* (vp - vpw) ; |
---|
94 | |
---|
95 | J = cat(3,L,u,v) ; |
---|