Addition of the distanceImage method (dynamic programmation)