[37] | 1 | function 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 | |
---|
| 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 | % XYZ components |
---|
| 74 | X = I(:,:,1) ; |
---|
| 75 | Y = I(:,:,2) ; |
---|
| 76 | Z = I(:,:,3) ; |
---|
| 77 | |
---|
| 78 | x = X/Xw ; |
---|
| 79 | y = Y/Yw ; |
---|
| 80 | z = Z/Zw ; |
---|
| 81 | |
---|
| 82 | L = 116 * f(y) - 16 ; |
---|
| 83 | a = 500*(f(x) - f(y)) ; |
---|
| 84 | b = 200*(f(y) - f(z)) ; |
---|
| 85 | |
---|
| 86 | J = cat(3,L,a,b) ; |
---|
| 87 | |
---|
| 88 | function b=f(a) |
---|
| 89 | sp = find(a > 0.00856) ; |
---|
| 90 | sm = find(a <= 0.00856) ; |
---|
| 91 | k = 903.3 ; |
---|
| 92 | b=zeros(size(a)) ; |
---|
| 93 | b(sp) = a(sp).^(1/3) ; |
---|
| 94 | b(sm) = (k*a(sm) + 16)/116 ; |
---|