Generate a random spanning tree of the
RGB cube, and a random spanning tree of the pixel grid, by randomising the edge weights and finding a minimal spanning tree, then do a simultaneous breadth-first search of these trees to obtain a bijection between the
RGB cube and the pixel grid. Compare with
http://allrgb.com/wilson-00