A method for defining analogue circuits for the minimisation of discrete functionals: an image processing application