Code covered by the BSD License

### Highlights from RGB to HSL

• hsl2rgb(hsl)Converts Hue-Saturation-Luminance Color value to Red-Green-Blue Color value
• rgb2hsl(rgb)Converts Red-Green-Blue Color value to Hue-Saturation-Luminance Color value
• View all files
3.33333
3.3 | 3 ratings Rate this file 13 Downloads (last 30 days) File Size: 1.58 KB File ID: #3360 Version: 1.0

# RGB to HSL

### Suresh Joel (view profile)

29 Apr 2003 (Updated )

Convert from RGB to HSL and HSL to RGB.

File Information
Description

Functions to convert RGB colorspace to HSL colorspace and vice-versa.

Acknowledgements

This file inspired Hsl2rgb And Rgb2hsl Conversion.

MATLAB release MATLAB 5.3.1 (R11.1)
MATLAB Search Path
`/`
08 Jun 2016 Baptiste

### Baptiste (view profile)

"RGB values have to be between 0 and 1"

This file look like a bit out of date now :s

22 Jan 2015 Daniel

### Daniel (view profile)

Remove the second last line in both functions to increase the precision (`rgb=round...`)

29 Sep 2011 David Holdaway

### David Holdaway (view profile)

without the change it returns whenever you have a 1,1,1 vector. With the change suggested it works ok. I don't like the treatment of all the same colour (e.g. [a,a,a]) though, it should interpolate the change in other colours rather than just turning it to [0,0,0]. I added the following block
if(mx-mn)==0,%if all three colors have same value,
if i==1
hsl(i,2)=0;%then s=0 and
hsl(i,1)=0;%h is undefined but for practical reasons 0
elseif i==2
hsl(i,2)=hsl(i-1,2);%take previous value
hsl(i,1)=hsl(i-1,1);%take previous value
else
hsl(i,2)=2*hsl(i-1,2)-hsl(i-2,2);%interpolate
if hsl(i,2) > 1
hsl(i,2) =1;
elseif hsl(i,2) < 0
hsl(i,2) =0;
end
hsl(i,1)=2*hsl(i-1,1)-hsl(i-2,1);%interpolate
if hsl(i,1) > 1
hsl(i,1) =1;
elseif hsl(i,1) < 0
hsl(i,1) =0;
end
end
continue;
end;

15 Feb 2005 daniel weiler

BUG-REPORT!

Please replace the last return statement with continue... or there will be bad surprises

Comment only