[Important edit:] Fixed bugs in source code that caused the search in colorspace to fail (int->long to prevent overflow, max()->min() to prevent dark pixels to remain max() actually does that, but it makes the images bland and uninteresting. min() makes images with more contrast and paradoxically causes less dark pixels to remain at the very end.) Also replaced the min() altogether in favor of grayscale value for the third variant. This didn't reproduce interesting results with the other variants. Variant 2 is discouraged as it has no pros compared to the other two at all. It's only included for completeness.
I got this idea from fejesjocouser fejesjoco's algorithm and wanted to play a bit and wrote this, so I started to write my own algorithm from scratch.
This alghorithmalgorithm: