A Variational Method for the Optimization of Tone Mapping Operators