Example 14.  Rendering 3-D Depth in an RGB Image Using Nested Subsets and Permutations

The equation for (sequential) combinatorial complexity is:

c = n! / (n-k)!

where c is the number of uniquely ordered sets of length k elements that can be picked from a pool of n elements.

If one has a deck of five playing cards, e.g., 10, Jack, Queen, King, Ace, there are only 60 hands of three cards each that can be laid out from left to right. Many of these hands are straights: {J, Q, K}. Hand {K, Q, J} is also included in the possible 60, because unlike a normal set, this is an ordered set.  Sequence matters, as it does in these written words.

Analogously, if we have only five grayscale levels available (e.g., {0, 0.25, 0.5, 0.75, 1.0}) there are 60 possible RGB color triplets.  They include: {0, 0.25, 0.5}, and its reverse order: {0.5, 0.25, 0}, but they do NOT include any subsets with duplicate {0, 0.75, 0.75} or triplicate values {1, 1, 1}.

By considering only {R, G, B} triplet ordered sets, the complexity equation reduces to:

c = n! / (n-3)!

The variable n can now be thought of as the number of grayscale levels. Complexity is now the number of colors in the entire palette.  This palette size increases rapidly as the number of grayscale values (per channel) increase. For n=5, c=60, as described for the playing cards.

Let's look at the 60-value palette of RGB triplets.  Instead of drawing these 60 values as a one dimensional line, we will partition the triplets into a 6 (width) by 10 (height) block of colors .  This looks like an ordinary palette, as shown below.

Image 14.1.  A complete palette using five grayscale levels from ordered sets.

Now, by analogy, we will no longer deal from a stack of five cards. Instead, we will deal all possible hands (six) from 10 pre-sorted stacks of cards.  That still leads to 60 possible hands - the complete ordered set for n = 5, k  =3.    In other words, we are no longer using a simple nesting scheme of r, g, b indices as  in the first image. Again, the results are partitioned into six columns of the image (or palette) for viewing in a rasterized format.  More so than the previous image, Mach bands develop between some of the colors, and a 3-D effect is observed.  To see this effect better, do not focus very long on your computer screen.  Look away at a distant object, then look back for a moment.  The three dimensionality is seen best as your eyes refocus.  This image can be screen captured and transferred to another program, such as Adobe Photoshop.  Adjusting the brightness and contrast can enhance the psychophysics of the 3-D effect on an idiosyncratic basis.

Image 14.2.  A complete palette using five grayscale levels from ordered sets that were permuted after presorting.

Note that one can display all 60 values of this RGB palette in a Schroedinger cube, as shown below. 10 groups of 'zigzag' lines are observed.  These groups are due to presorting, and the saw tooth appearance is caused by each of the ten permutation commands (see computer code).

Image 14.3.  Schroedinger cube for the 60 RGB triplet values used in Image 14.2.

Now, we redraw 14.2 using 11 grayscale values: grayset={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}.  By analogy, 6 hands are dealt from 120 presorted decks of cards.  This required more computer code to automatically presort - see code.

Image 14.5.  A complete palette using ten grayscale levels from ordered sets that were permuted after presorting.

Note that one can display all 720 values of this RGB palette in a Schroedinger cube, as coded below. 120 groups of 'zigzag' lines are observed that are due to the selection of 120 RGB subsets, and the saw tooth appearance is caused by each subset's subsequent permutation.

Image 14.6.  Schroedinger cube for the 720 RGB triplet values used in Image 14.5.

Suggestions for further work include the rather ambitious goal of modifying an ordinary 2-D (width, height) color photograph or RGB video signal to produce 3-D perspective on computer monitors (such as yours) and broadcast television.

Source code is given here in .nb format and .PDF format.