source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vlutil/toolbox/xyz2lab.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.0 KB
Line 
1function J=xyz2lab(I)
2% XYZ2LAB  Convert XYZ to LAB
3%   J = XYZ2LAB(I) converts the image from XYZ format to LAB format.
4%
5%   XYZ2LAB(I,'illuminant') uses the specified illuminant. The
6%   following illuminant are supported: 'A', 'B', 'C', 'E', 'D50',
7%   'D55', 'D65', 'D75', 'D93'. By default, 'E' is usedd.
8%
9%   See also XYZ2LUV().
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
30if nargin < 2
31  illuminant='E' ;
32end
33
34switch 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 ;
62end
63
64J=zeros(size(I)) ;
65
66% Reference white
67xw = 1/3 ;
68yw = 1/3 ;
69Yw = 1.0 ;
70Xw = xw/yw ;
71Zw = (1-xw-yw)/yw * Yw ;
72
73% XYZ components
74X = I(:,:,1) ;
75Y = I(:,:,2) ;
76Z = I(:,:,3) ;
77
78x = X/Xw ;
79y = Y/Yw ;
80z = Z/Zw ;
81
82L = 116 * f(y) - 16 ;
83a = 500*(f(x) - f(y)) ;
84b = 200*(f(y) - f(z)) ;
85
86J = cat(3,L,a,b) ;
87
88function b=f(a)
89sp = find(a  > 0.00856) ;
90sm = find(a <= 0.00856) ;
91k = 903.3 ;
92b=zeros(size(a)) ;
93b(sp) = a(sp).^(1/3) ;
94b(sm) = (k*a(sm) + 16)/116 ;
Note: See TracBrowser for help on using the repository browser.