-modulate in LCH colorspace

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

-modulate in LCH colorspace

Post by GreenKoopa »

I am attempting to reduce saturation in LCH colorspace, but am getting unexpected results.

Code: Select all

convert -size 256x200 gradient:#000-#F00 -set option:modulate:colorspace HSL -modulate 100,50,100 a.png

convert -size 256x200 gradient:#000-#F00 -set option:modulate:colorspace LCH -modulate 100,50,100 b.png

convert -size 256x200 gradient:#000-#F00 -set option:modulate:colorspace LCHuv -modulate 100,50,100 c.png
ImageMagick 7.0.2-5 Q16 x64 2016-07-22
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -modulate in LCH colorspace

Post by fmw42 »

I am not sure IM allows LCH in that option.

In fact, I do not see a corresponding -define for modulate:colorspace that would identify which colorspaces are allowed.

The code at line 3435 of enhance.c does not list LCH, but does list HCL, HCLp, HSI, HSB, HSL, LCHab and LCHuv.

The documentation at http://www.imagemagick.org/script/comma ... colorspace does not list LCH, but

Code: Select all

convert -list colorspace
does list it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -modulate in LCH colorspace

Post by snibgo »

The LCH (aka LCHab) and LCHuv colorspaces have the neutral position of the Chroma channel at 50%.

This is different to HSL, HCL etc where the Saturation or Chroma is neutral at 0%.

But the formulae in effect.c ModulateLCHuv() etc are the same as ModulateHSL() etc. So the effect of modulating Chroma of LCH will be very different to that of HCL. For example, "-modulate 100,50,100" will multiply the channel by 0.5, which will always reduce saturation in HCL. But in LCHuv, it may increase or reduce saturation (and even change the colour, eg red can become cyan).
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -modulate in LCH colorspace

Post by GreenKoopa »

I knew 50% was neutral for a and b because they can be negative. But C?? I thought C and H were simply the polar version of a and b.

I didn't expect the output for cases e and g.

Code: Select all

convert -size 100x256 gradient:#000-#F00 d.png
convert d.png -set option:modulate:colorspace LCH -modulate 50,100,100 e.png
convert -size 100x256 gradient:#000-#F00 -set option:modulate:colorspace LCH -modulate 50,100,100 f.png
convert -size 100x256 gradient:#000-#F00 -set option:modulate:colorspace LCH -modulate 100,50,100 g.png
convert -size 100x256 gradient:#000-#F00 -set option:modulate:colorspace LCH -modulate 100,100,50 h.png
convert d.png e.png f.png g.png h.png +append i.png
i.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -modulate in LCH colorspace

Post by snibgo »

The L channels of LCH and LAB are the same.
GreenKoopa wrote:I thought C and H were simply the polar version of a and b.
I've often seen statements like that, but I don't know precisely what it means.

The "H" channel of LCH (aka LCHab) isn't exactly what we normally think of as Hue.

The "C" channel is Chroma, but the neutral point is at 50%. If we want to decrease saturation, we should push this value towards 50%. If we simply halve the value, then C=100% will become C=50% (removing colour entirely), but 50% will become 25% (giving it colour), 40% will become 20% (increasing saturation), 60% will become 30% (which is the other side of 50% so the colour will change) and so on.

Are we confused? I am. But wait, it gets worse.

LCH has a different gamut to sRGB. I think that all colours expressible in sRGB have one (or two!) equivalents in LCH [see *EDIT]. But the converse isn't true.

For example, LCH=(50%,50%,10%) is a shade of gray. Fair enough.

LCH=(50%,25%,10%) translates to sRGB (-267%,56%,71%). The negative number will often be clamped to zero.

And LCH=(50%%,10%%,10%%) translates to sRGB (-563%,56%,71%).

Eek.

*EDIT: I was wrong; some sRGB colours are not expressible in LCH. sRGB pure blue #00f has C=102%, so is out-of-gamut for LCH.
snibgo's IM pages: im.snibgo.com
Post Reply