


hsl2hsv - Convert hue-saturation-luminance colors to hue-saturation-value.
USAGE
y = hsl2hsv(x)
x Nx3 RGB matrix (values in [0..1])

0001 function y = hsl2hsv(x) 0002 0003 %hsl2hsv - Convert hue-saturation-luminance colors to hue-saturation-value. 0004 % 0005 % USAGE 0006 % 0007 % y = hsl2hsv(x) 0008 % 0009 % x Nx3 RGB matrix (values in [0..1]) 0010 0011 % Copyright (C) 2013 by Michaƫl Zugaro 0012 % 0013 % This program is free software; you can redistribute it and/or modify 0014 % it under the terms of the GNU General Public License as published by 0015 % the Free Software Foundation; either version 3 of the License, or 0016 % (at your option) any later version. 0017 0018 % Check number of parameters 0019 if nargin < 1, 0020 error('Incorrect number of parameters (type ''help <a href="matlab:help hsl2hsv">hsl2hsv</a>'' for details).'); 0021 end 0022 if ~isdmatrix(x) || size(x,2) ~= 3 || any(x(:)<0) || any(x(:)>1), 0023 error('Incorrect HSL matrix (type ''help <a href="matlab:help hsl2hsv">hsl2hsv</a>'' for details).'); 0024 end 0025 0026 % Convert from HSL to HSV 0027 0028 h = x(:,1); 0029 s = x(:,2); 0030 l = x(:,3); 0031 0032 H = h; 0033 S = s; 0034 in = l <= 0.5; 0035 S(in) = S(in) .* l(in); 0036 S(~in) = S(~in) .* (1-l(~in)); 0037 V = l + S; 0038 in = V > 0; 0039 S(in) = 2 * S(in) ./ V(in); 0040 S(~in) = 0; 0041 0042 0043 y = Clip([H S V],0,1); 0044 0045 0046 % in = l <= 0.5; 0047 % s(in) = s(in) .* l(in); 0048 % s(~in) = s(~in) .* (1-l(~in)); 0049 % l = l + s; 0050 % 0051 % in = l > 0; 0052 % s(in) = 2 * s(in) ./ l(in); 0053 % s(~in) = 0; 0054 % 0055 % H = h; 0056 % S = s; 0057 % V = l;