Like its sister program rectify, flux uses a simple Monte Carlo algorithm to converge towards a target image. This time the algorithm starts from a randomization of the target and progresses by choosing, at random, two nearest-neighbor pixels and attempting to swap their RGBA (red, green, blue, alpha) values. Once again, a simple Metropolis acceptance rule is used to determine whether the trial pixel swap is kept.

The algorithm results in the flow of pixels across the canvas as they attempt to find their optimal target location. The resulting images bear some resemblance to iron filings being manipulated by an external magnetic field.

Full details can be found on the flux GitHub page.


The code can be downloaded and installed as follows:

git clone https://github.com/lohedges/flux.git
cd flux
sudo make install


To get started there are a few test images included in the examples folder. Running flux as shown below converges towards a target image of Manhattan, NYC. The program executes 10 thousand Monte Carlo sweeps and saves a total of 1000 images at logarithmically spaced intervals. All of the output is saved to a directory called nyc, which will be created if it doesn't already exist.

cd examples
flux nyc.png -d nyc -i 10000 -f 1000 -l

The following short movie shows the output of the program. A striking high contrast cityscape appears out of random noise.

As another example, try running flux on the zebra photograph included in the examples directory. The movie below shows an example of the program output.

flux zebra.png -d zebra -i 100000 -f 1000 -l

Flux can also be run in reverse mode. Here the program starts from the target image and converges towards a fully randomized state. It's cool to watch the image slowly dissolve; it's almost as if the pixels have become detached from the canvas and then been blown away.

flux zebra.png -d zebra_reverse -i 100000 -f 1000 -l -r