File Exchange

image thumbnail

hsl2rgb and rgb2hsl conversion

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

18 Downloads

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 (2020). hsl2rgb and rgb2hsl conversion (https://www.mathworks.com/matlabcentral/fileexchange/20292-hsl2rgb-and-rgb2hsl-conversion), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

DGM

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...

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

where I is the uint8 image you just opened with imread

molanyu

shit

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.

Leox91

Thanks but this does not work in Matlab2016

rgb2hsl is not working

Hermawan -

then what should i do sir.?

Ruben

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

Works as advertised

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

Inspired by: RGB to HSL

Inspired: hslcolormap