Algorithm: Pick a random unused colour and find a place where nearby pixels are similar, then place it there; repeat until all colours are placed.
Code: https://gitlab.com/snippets/1752310