Generate a random spanning tree of the
RGB cube, and a random spanning tree of the pixel grid, using Wilson's algorithm, then do a simultaneous breadth-first search of these trees to obtain a bijection between the RGB cube and the pixel grid. Code at
https://gist.github.com/robinhouston/9360681