Home > FMAToolbox > Plot > hsv2hsl.m

hsv2hsl

PURPOSE ^

hsv2hsl - Convert hue-saturation-value colors to hue-saturation-luminance.

SYNOPSIS ^

function y = hsv2hsl(x)

DESCRIPTION ^

hsv2hsl - Convert hue-saturation-value colors to hue-saturation-luminance.

  USAGE

    y = hsv2hsl(x)

    x              Nx3 RGB matrix (values in [0..1])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y = hsv2hsl(x)
0002 
0003 %hsv2hsl - Convert hue-saturation-value colors to hue-saturation-luminance.
0004 %
0005 %  USAGE
0006 %
0007 %    y = hsv2hsl(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 hsv2hsl">hsv2hsl</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 hsv2hsl">hsv2hsl</a>'' for details).');
0024 end
0025 
0026 % Convert HSV to HSL
0027 h = x(:,1);
0028 s = x(:,2);
0029 v = x(:,3);
0030 
0031 H = h;
0032 S = s .* v;
0033 L = (2-s).*v;
0034 in = L <= 1;
0035 S(in) = S(in) ./ L(in);
0036 S(in&v==0) = 0;
0037 S(~in) = S(~in) ./ (2-L(~in));
0038 S(~in&s==0&v==1) = 0;
0039 L = L/2;
0040 
0041 y = Clip([H S L],0,1);

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005