File Exchange

image thumbnail

hsl2rgb and rgb2hsl conversion

version (2.22 KB) by Vladimir Bychkovsky
Functions to convert between RGB and HSL


Updated 16 Jun 2008

No License

This package consists of 3 files: rgb2hsl.m, hsl2rgb.m, and hsltest.m. The first two perform color conversion between HSL and RGB color spaces for 1d and 2d arrays(images). The last file includes unit tests for conversion.

Cite As

Vladimir Bychkovsky (2021). hsl2rgb and rgb2hsl conversion (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Muhammad Falah

works perfect, thank you!

Leonardo Starling

I'm using it in Matlab 2016 to convert a colormap from RGB to HSL and it's working perfectly!


These conversion tools work fine. Read the synopsis. The inputs need to be of class 'double' or with data range of [0 1].

If you have IPT installed, you can simply use im2double() or to convert any standard image to 'double'.
If you don't have IPT, just do double(mypictureofthings)./255

Strangely enough, in R2009b this code fails silently when fed a uint8 image, but R2015b actually produces an error message. Furthermore, this seems to work fine for 'single' images in R2009b, but not in R2015b. This might be part of the confusion, and is likely due to changes to the built-in HSV conversion tools.

Ben Holmes

Works just great, not sure why this isn't implemented in MATLAB directly.

cah cet

hsl2rgb and rgb2hsl conversion do NOT work...

Ross Marchant

hsl = rgb2hsl(double(I)./256);

where I is the uint8 image you just opened with imread

Tudith langer



Shahadat Hossain

The command rgb2hsl doesnt work in matlab 2016. One member has put a comment that it needs to be converted to double instead of uint8. But how can I do this. please help me.


Thanks but this does not work in Matlab2016

Alper Türker

rgb2hsl is not working

Hermawan -

then what should i do sir.?


rgb2hsl is not working properly. It needs to convert the results of some operations to double format instead of uint8

Patrick Mineault

Works as advertised

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: RGB to HSL

Inspired: hslcolormap

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!