An Optimisation Approach for Using Contextual Information in Conputer Vision