A computer-implemented method of preprocessing, prior to encoding using an external encoder, image data using a preprocessing network, the preprocessing network comprising an artificial neural network comprising a set of inter-connected weights, the method comprising: receiving, at the preprocessing network, image data from one or more images; and processing the image data using the preprocessing network, by applying the weights of the preprocessing network to the image data, to generate an output pixel representation, of the one or more images, for encoding with the external encoder, wherein the weights of the preprocessing network are trained using back propagation and gradient descent to optimise a combination of: at least one quality score indicative of the quality of the output pixel representation of the one or more images; and a rate score indicative of the bits required by the external encoder to encode the output pixel representation of the one or more images, and wherein the at least one quality score and the rate score are calculated using a virtual codec module comprising one or more mathematically differentiable functions configured to emulate an encoding process, the virtual codec module being configured to receive, from the preprocessing network, pixel representations of input images, and to produce distorted pixel representations of the input images using the one or more mathematically differentiable functions, the virtual codec module comprising a frequency transform component, a quantization and encoding component, and a dequantization and inverse frequency transform component. receiving, at the preprocessing network, image data from one or more images; and processing the image data using the preprocessing network, by applying the weights of the preprocessing network to the image data, to generate an output pixel representation, of the one or more images, for encoding with the external encoder, wherein the weights of the preprocessing network are trained using back propagation and gradient descent to optimise a combination of: at least one quality score indicative of the quality of the output pixel representation of the one or more images; and a rate score indicative of the bits required by the external encoder to encode the output pixel representation of the one or more images, and wherein the at least one quality score and the rate score are calculated using a virtual codec module comprising one or more mathematically differentiable functions configured to emulate an encoding process, the virtual codec module being configured to receive, from the preprocessing network, pixel representations of input images, and to produce distorted pixel representations of the input images using the one or more mathematically differentiable functions, the virtual codec module comprising a frequency transform component, a quantization and encoding component, and a dequantization and inverse frequency transform component. at least one quality score indicative of the quality of the output pixel representation of the one or more images; and a rate score indicative of the bits required by the external encoder to encode the output pixel representation of the one or more images, and wherein the at least one quality score and the rate score are calculated using a virtual codec module comprising one or more mathematically differentiable functions configured to emulate an encoding process, the virtual codec module being configured to receive, from the preprocessing network, pixel representations of input images, and to produce distorted pixel representations of the input images using the one or more mathematically differentiable functions, the virtual codec module comprising a frequency transform component, a quantization and encoding component, and a dequantization and inverse frequency transform component.