1. 2011
    Mar
    28

    Two complex color functions

    In the process of graphing some complex valued functions, I figured out a couple of neat coloring schemes that I thought might be worth sharing. Both schemes share the same hue and saturation functions:

    $$H = \arg{z}-\frac{\pi}{2}$$
    $$S = \abs{\frac{\imag{z}}{z}}$$

    They differ in the third component, though. The one which I will arbitrarily designate “color scheme 1” (because I like it better) is defined in HSL color space, and has a luminosity function of

    $$L = \frac{1}{2}\biggl[1 - 2^{20}\abs{S - \frac{1}{2}}^{20}\sgn\biggl(S - \frac{1}{2}\biggr)\biggr]$$

    where \(S\) is the saturation value. This maps all real or nearly real numbers to white, all imaginary or nearly imaginary numbers to black, and other complex numbers to varying hues depending on their phase.

    The other one, “color scheme 2,” has a value (brightness) function of

    $$V = 1 - \frac{S}{4}$$

    This maps all real or nearly real numbers to white, and all other numbers to varying hues, again depending on their phase. Positive imaginary numbers are red, negative imaginary numbers are cyan.

    Note that both functions are undefined at \(z = 0\). If you implement these you …

  2. 2010
    Jun
    13

    CMYK to RGB conversion

    It certainly took long enough, but after an hour or so of hunting I finally tracked down the formula that the ImageMagick color converter uses to convert CMYK colors into RGB. I rewrote it a little to make the expression more illuminating:

    $$r = Q_R (1 - c / Q_R)(1 - k / Q_R)$$
    $$g = Q_R (1 - m / Q_R)(1 - k / Q_R)$$
    $$b = Q_R (1 - y / Q_R)(1 - k / Q_R)$$

    for a CMYK color point \((c,m,y,k)\) and RGB color point \((r,g,b)\). The tricky part to locate was the constant \(Q_R\), and a related constant \(Q_S\), which ImageMagick calls QuantumRange and QuantumScale respectively.

    • \(Q_R\) is the range that each of the color values can take on, so if each of your channels (red, green, blue, cyan, magenta, yellow, black) is given by a number from 0–255, for example, \(Q_R\) would be 255.
    • \(Q_S\) is actually just the reciprocal of \(Q_R\). I suspect they give it a different name only because floating-point division is pretty inefficient so it saves some CPU cycles to precompute \(1/Q_R\).

    If anyone wants to track it down themselves, the algorithm is in the ConvertCMYKToRGB function in the ImageMagick source code (line 1327 of colorspace …