Page 1 of 1

possible bug reporting hsl colors with txt: in IM 6.4.1-8

Posted: 2008-06-18T19:06:16-07:00
by fmw42
Let me start this again as I forgot that hue needs to be expressed in degrees.

Consider: hue=cyan=180deg, saturation=50% and lightness=50%

convert -size 1x1 xc:"hsl(180,50%,50%)" txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: (16384,49151,49151) #4000BFFFBFFF hsl(25%,75%,75%)

First thing is that hue is now expressed as percent (???) and all values are changed. I don't think this is what was intended.

If txt: is supposed to convert this from hsl and report as rgb, then the value should be:
(25%,75%,75%) which is just the complement of (25%,75%,75%).
See next paragraph.

You can find out what the correct rgb color should be with online HSL to RGB converters at: http://monc.se/kitchen/stew/hsl/ or at http://serennu.com/colour/hsltorgb.php by entering 180deg,50%,50% i.e. 180,50,50. The result is from both: rgb(64,191,191) or rgb(25%,75%,75%).

If one does the following in IM to convert the hsl(180,50%,50%) to rgb:

convert -size 1x1 xc:"hsl(180,50%,50%)" \
> -colorspace HSL -channel RGB -separate +channel \
> \( -clone 0 -colorspace HSL \
> -clone 0 -compose CopyRed -composite \
> -clone 1 -compose CopyGreen -composite \
> -clone 2 -compose CopyBlue -composite \) \
> -delete 0-2 -colorspace RGB txt:-
# ImageMagick pixel enumeration: 1,1,65535,rgb
0,0: (49151,61439,36863) #BFFFEFFF8FFF rgb(75%,93.75%,56.25%)

where one gets: rgb(75%,93.75%,56.25%) which is also incorrect as the correct value should be rgb(25%,75%,75%).

Here are the comparison images:

HSL defined:
convert -size 100x100 xc:"hsl(180,50%,50%)" cyan_hsl_180_50_50.png
Image

Correct RGB color:
convert -size 100x100 xc:"rgb(25%,75%,75%)" cyan_rgb_25_75_75.png
Image

Note these are 50% saturated cyan and not fully saturated cyan (namely this color)

Another example:

Pure cyan in hsl is 180,100%,50%:

convert -size 1x1 xc:"hsl(180,100%,50%)" txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: ( 0,65535,65535) #0000FFFFFFFF cyan

This comes out correct.


Similarly close to the peaks in the hexcone, one gets reasonable values also, namely white or black.

Any hue (in this case red) at any saturation (in this case full) and full lightness should be white:

convert -size 1x1 xc:"hsl(0,100%,100%)" txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: (65535,65535,65535) #FFFFFFFFFFFF white

which is the correct rgb color

Similarly

Any hue (in this case cyan) at any saturation (in this case zero) and zero lightness should be black:

convert -size 1x1 xc:"hsl(180,0%,0%)" txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: ( 0, 0, 0) #000000000000 black

which is the correct rgb color

Similarly anywhere along the axis of the hexcone should be gray:

So cyan at zero saturation and 50% lightness should be gray50:

convert -size 1x1 xc:"hsl(180,0%,50%)" txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: (32768,32768,32768) #800080008000 grey50

which is correct.


My hope is that providing an HSL color to txt: will have it report the converted RGB color back with the proper label of rgb and not hsl. But I don't know if this is what was intended.


It looks to me like the hsl to rgb conversion possibly works, except away from the hexcone axis and outside edge, i.e. the problem is mainly in the saturation handling (or it is just some strange complementing of values somewhere in the handling of this situation).

Hope these are enough clues to help you track this down.

Sorry for the error in my first go around with this message.

Re: possible bug reporting hsl colors with txt: in IM 6.4.1-8

Posted: 2008-06-19T07:17:14-07:00
by magick
The problem you reported is fixed in the subversion trunk.