1
$\begingroup$

In Python, I have been attempting to generate a slightly different-from-normal RGB cube with the only difference being that the grayscale is reversed, just for fun. My code generates the RGB cube and afterwards, the CMY cube (via central inversion) just fine, as can be seen from the pictures below:

RGB Cube Generated
CMY Cube Generated

Since attempting to apply various transformations, I have realized I am in need of a transformation that I know not how to formulate mathematically.


The black vertex is connected to red, green, and blue vertices by at least ONE edge of the cube, whereas the white vertex is connected to the red, green, and blue vertices by at least TWO edges of the cube. Thus, any physical transformation attempting to reverse these properties is utterly impossible; the minimum number of edges between any two vertices would remain unaffected.

What I believe I need to do, rather than apply a physical transformation, is to consider the color gradient lines directly connecting white to red, to green, and to blue (diagonals along a particular face of the cube). These lines must be "swapped" with the edges of the cube that connect black to red, to green, and to blue, respectively.

Just as well, the cube edges connecting white to cyan, to magenta, and to yellow must be "swapped" with the face diagonals connecting black to cyan, to magenta, and to yellow, respectively.

Everything "in between" must be swapped accordingly as well. (And thus, the length of each of these lines will be changed).

Is this even possible?
If so, is this akin to turning the cube "inside out" along the greyscale axis?
Is there an existing transformation that mathematically describes exactly this?
If so, where might I find more information on this? Where might I begin in trying to deduce it for myself?

Please let me know if any of my own considerations and/or deductions are blatantly incorrect. Thanks for reading and for your consideration! <3

EDIT (To aid in visualization):
Imagine three separate lines originating from the white vertex of the RGB cube. One runs to the red vertex, the second to the green vertex, and the third to the blue vertex (along face diagonals on the cube).
Additionally, imagine three MORE separate lines originating from the black vertex of the RGB cube. One runs to the red vertex, the second to the green vertex, and the third to the blue vertex (along edges of the cube).
Now, consider the red, green, and blue vertices as fixed in place. Imagine with one hand you pinch the white vertex and with the other you pinch the black vertex.
Finally, disregarding physicality, imagine you attempt to pull them through each other along the direction parallel to the greyscale axis.
Once the transformation is complete, the black vertex resides where the white vertex once did and vice versa. The black-associated lines (once edges of the cube) are now face diagonals of the cube in the exact same position and orientation that the white-associated lines first occupied. The white-associated lines (one face diagonals of the cube) are now edges of the cube in the exact same position and orientation that the black-associated lines first occupied. The red, green, and blue vertices are in the same spots.
(This is the transformation I want to describe)

$\endgroup$
7
  • $\begingroup$ Could you clarify the sense in which you want to "preserve the rest" of the cube? Do you want to invert the brightness but preserve the hue? The transformation that inverts the sum r+g+b but preserves the 3-way ratio r:g:b is pretty easy to compute. $\endgroup$
    – Karl
    Commented Apr 2 at 0:59
  • $\begingroup$ ...but I guess the transformation I proposed produces values outside the cube e.g. $(1,0,0)\mapsto(2,0,0).$ In these cases, operating on the inverse color works better: $(0,1,1)\mapsto(0,.5,.5).$ $\endgroup$
    – Karl
    Commented Apr 2 at 1:18
  • $\begingroup$ I can't see the colours inside your cube. sagecell.sagemath.org/… $\endgroup$
    – PM 2Ring
    Commented Apr 2 at 1:32
  • $\begingroup$ I guess I am talking about "preserving" the color gradients in any given direction from any given starting point through this transformation. Although, the way I was thinking about doing this would change the effective length of each and the gradient would either lose or gain information depending on what was considered (because we are converting diagonals to edges and edges to diagonals). I am basically looking to "swap" the places of white and black such that white is connected to R, G, and B by AT LEAST 1 edge (rather than 2) and black to R, G, and B by AT LEAST 2 edges (rather than 1). $\endgroup$ Commented Apr 2 at 3:36
  • $\begingroup$ How about complementing the hues, then inverting all the RGB values? That will restore the hues and flip the grey values. I have efficient RGB complement code in Python: stackoverflow.com/a/40234924/4014959 $\endgroup$
    – PM 2Ring
    Commented Apr 3 at 4:56

1 Answer 1

1
$\begingroup$

You can convert to HSL color space, then invert to $L$ value e.g. $L' = 1-L$, then convert it back to RGB.

Although technically speaking this is not true grayscale though (you need the XYZ color space)

$\endgroup$
1
  • $\begingroup$ CIE XYZ is probably better than sRGB, but I'd prefer a more perceptually uniform space, like CIELUV, or the relatively new OKLCH. $\endgroup$
    – PM 2Ring
    Commented Apr 3 at 6:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .