1. A method of generating an image enhancement function for enhancing an input image comprising a plurality of pixels to form an enhanced output image comprising a plurality of pixels, the method comprising: receiving a reference image comprising a plurality of pixels; receiving an enhanced image comprising a corresponding plurality of pixels, wherein the enhanced image is derived from the reference image; calculating a plurality of lookup tables, wherein each lookup table maps a first plurality of pixel values to a second plurality of pixel values; and generating the image enhancement function which comprises a spatially varying function of the lookup tables and which, when applied to the input image, forms the output image, wherein the image enhancement function, when applied to the reference image, generates an approximation to the enhanced image.