I need to generate a color map which I am not sure exist. I have a 1024x1024 image which would contain 2^20 pixels. I have 3 color channels which each have 8 bits which would leave us with 2^24 possible colors. This means that there would actually be enough different pixel values for a unique value for a 4096x4096. This problem is easy to solve with non continuous colors where you simply use 4 bits of the final channel on both of the first two channels to create two 12 bit channels.

Here is an example of the non-continuous version:

Each of the individual sub-squares has a different blue value which gives us a unique value. This may be hard to see with the eye, as they are only changing by a very small amount. Using this technique, it is easy to fill up an entire 4096x4096 with unique, mathematically predictable colors.

Unfortunately, I have a new constraint where all three channels of the map must remain continuos. What I mean by this is that each individual neighboring pixels channel value does not change by more than one in value. For instance, a pixel with a red value of 10 may have direct neighbors with a red value of either 9, 10 or 11 The reason for this constraint is that when sampling from this texture, individual neighboring pixels may be sub-sampled and linear interpolated together and when going along the edge of the sub-boxes, this would result in inaccurate values.

To put it in a slightly different way, I need a function f and f^-1

f(x, y) = r, g, b

f^-1(r, g, b) = x, y (only existing in the original x,y range)

with r, g, b, being 8 bit numbers (the integers 0 - 255) and x and y being 10 bit numbers (the integers 0 - 1023). All neighboring r,g,b values must be continuous. By continuous, I mean that each individual neighboring pixels channel value does not change by more than one in each channel. Do such functions exist, and if so, what are they?

10more comments