Implementation of Kolmogorov and Zabih's algorithm