A Variational Approach to the Design of Early Vision Algorithms