Issue with color conversion IM 6.9.10.68 Q16 Mac OSX

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Issue with color conversion IM 6.9.10.68 Q16 Mac OSX

Post by fmw42 »

Converting back and forth between RGB and HSV is not working properly for a round trip.

IM 6.0.8.68

I start with blue, but end up with red whether or not I use -colorspace sRGB

# convert blue to hsv

convert xc:blue -colorspace hsv txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (43690,65535,65535) #AAAAFFFFFFFF hsv(240,100%,100%) <-- hue=240 is properly blue


# list hsv(240,100%,100%) in txt should return blue

convert xc:"hsv(240,100%,100%)" txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (65535,65535,65535) #FFFFFFFFFFFF hsv(360,100%,100%) <-- red


# make a swatch from (blue) hsv(240,100%,100%) comes out red (adding -colorspace sRGB does not change the result)

Code: Select all

convert xc:"hsv(240,100%,100%)" swatch.png

IM 7.0.8.68 behaves differently

magick xc:blue -colorspace hsv txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (43690,65535,65535) #AAAAFFFFFFFF hsv(240,100%,100%) <-- properly blue


magick xc:"hsv(240,100%,100%)" txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (157284,65535,65535) #FFFFFFFFFFFF hsv(864,100%,100%) <-- hue=864 is outside the range 0 to 360

# swatch comes out green

Code: Select all

magick xc:"hsv(240,100%,100%)" swatch.png

Note: I tested versions back to 6.9.9.10 and got the same bad behavior.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue with color conversion IM 6.9.10.68 Q16 Mac OSX

Post by fmw42 »

HSB works fine. I believe HSB and HSV are the same. So I have a workaround. Does Imagemagick not permit conversion between HSV and RGB?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue with color conversion IM 6.9.10.68 Q16 Mac OSX

Post by snibgo »

The problem is that HSV text output, for the hue channel, is in degrees (scale 0 to 360). But the input is a percentage (scale 0 to 100). For example:

Code: Select all

f:\web\im>%IMG7%magick xc:hsv(10,100%,100%) txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (6553.5,65535,65535)  #199AFFFFFFFF  hsv(36,100%,100%)
Tested with v7.0.8-64 and v6.9.9-50.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue with color conversion IM 6.9.10.68 Q16 Mac OSX

Post by fmw42 »

snibgo, the format listed for HSB and HSL show hue in degrees and the other values in percent. See https://imagemagick.org/script/color.php. U expect that it should be the same syntax for HSV. Also, it should be the same for input and output. It works fine for HSB, for example, which should be the same as HSV.

HSB:

Code: Select all

convert xc:blue -colorspace HSB txt:
# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: (43690,65535,65535) #AAAAFFFFFFFF hsb(240,100%,100%)

Code: Select all

convert xc:"hsb(240,100%,100%)" txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (0,0,65535) #00000000FFFF blue


HSV:

Code: Select all

convert xc:blue -colorspace HSV txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (43690,65535,65535) #AAAAFFFFFFFF hsv(240,100%,100%)

Code: Select all

convert xc:"hsv(240,100%,100%)" txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (65535,65535,65535) #FFFFFFFFFFFF hsv(360,100%,100%)


I suspect that HSV is not supported as input. Probably the same for HCL and HSI.
Post Reply