-colorspace LCHab

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
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

-colorspace LCHab

Post by GreenKoopa »

The C channel of LCHab is improperly scaled in memory, and so clips. The clipping is bad enough that even the sRGB colorspace does not quite fit in the current implementation of LCHab. It easily could be made to include all of Lab. I believe the valid channel ranges are:
L 0 - 100 (same value as in Lab)
C 0 - 182 (to cover Lab)
H 0 - 360°
The C channel appears to be implemented as +/-128 (the same as a & b). This not only causes clipping, but also unnecessary compression into 7 bits.

; Minimal rounding error is introduced in the sRGB > Lab > sRGB round trip.
> convert -size 1x1 xc:#00F -colorspace Lab -colorspace sRGB txt:-
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (0%,0.00610361%,100%) #00000004FFFF srgb(0%,0.00610361%,100%)

; Clipping occurs in the sRGB > LCHab > sRGB round trip.
> convert -size 1x1 xc:#00F -colorspace LCHab -colorspace sRGB txt:-
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (12.52%,4.68757%,96.463%) #200D0C00F6F1 srgb(12.52%,4.68757%,96.463%)

; Here the clipping in the middle C channel can be seen.
> convert -size 1x1 xc:#00F -colorspace LCHab txt:-
# ImageMagick pixel enumeration: 1,1,65535,lchab
0,0: (32.3033%,100%,85.0797%) #52B2FFFFD9CD lchab(32.3033%,100%,85.0797%)

ImageMagick 6.8.8-1 Q16 x64 2013-12-25 on Windows 7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorspace LCHab

Post by snibgo »

LCH is also bad, hardly surprisingly. My usual round-trip test shows:

Code: Select all

YCC	7191.13	0.10973
YDbDr	5912.42	0.0902177
LCHuv	937.163	0.0143002
YUV	265.687	0.00405413
YIQ	156.837	0.00239318
XYZ	152.622	0.00232887
LMS	71.7158	0.00109431
LCHab	63.9958	0.000976513
LCH	63.9958	0.000976513
The first number should be close to 1.
IM v6.8.8-0 on Windows 7.

Code: Select all

"%IX%convert" hald:8 h8.png

"%IX%convert" -list colorspace >%TEMP%\cs2.lis

set SRC=h8.png

del csrt.csv

for /F %%a in (%TEMP%\cs2.lis) do (
  "%IX%convert" %SRC% -colorspace %%a -colorspace sRGB x.png

  "%IX%compare" -metric RMSE %SRC% x.png NULL: 2>>csrt.csv
  cEcho /Ocsrt.csv /s" %%a"
)

cSort /icsrt.csv /ocsrt.csv /k0 /f" " /r
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -colorspace LCHab

Post by magick »

Offsets are required for some colorspaces to fit it in unsigned quantums, e.g. 0..65535. For HDRI, we could remove the offsets since HDRI supports negative values. We spent a considerable amount of time ensuring the colorspace transforms were correct per Bruce Lindblooms equations. ImageMagick results appear to match the output of his colorspace calulator. However, in case we overlooked something, see magick/gems.c and magick/colorspace.c for the entire set of colorspace transforms. If you spot a flaw, the IM developers are interested in hearing about it, particularly if the flaw is accompanied with a patch!
Post Reply