Note: this isn't Efros & Freeman's code, just my implementation of it.
Caveats:
For now, the code only works on grayscale images.
Extending it to color is straightforward. The minimum error cut is
not yet implemented, but is on my list of things to do.