No BSD License  

Highlights from
RGB to HSL

4.0

4.0 | 1 rating Rate this file 24 Downloads (last 30 days) File Size: 1.58 KB File ID: #3360

RGB to HSL

by Suresh Joel

 

29 Apr 2003 (Updated 30 Apr 2003)

Convert from RGB to HSL and HSL to RGB.

| Watch this File

File Information
Description

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

Acknowledgements
This submission has inspired the following:
hsl2rgb and rgb2hsl conversion
MATLAB release MATLAB 5.3.1 (R11.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
15 Feb 2005 daniel weiler

BUG-REPORT!

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

29 Sep 2011 David Holdaway

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;

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
color Suresh Joel 22 Oct 2008 07:00:42
hue saturation luminance color colorspace Suresh Joel 22 Oct 2008 07:00:42
color Mehdi Karimi 04 Nov 2010 15:49:57
hue saturation luminance color colorspace Mehdi Karimi 04 Nov 2010 15:50:02
color yue ms 13 Jul 2011 18:24:19

Contact us at files@mathworks.com