An image encoder, comprising a processor configured to execute instructions that cause the processor to: obtain a lower dynamic range, LDR, image corresponding to a high dynamic range, HDR, image, the lower dynamic range image being obtainable from the high dynamic range image by a dynamic range reduction process and containing the same scene as the high dynamic range image; generate a prediction function based on the high dynamic range image and the lower dynamic range image, wherein generating the prediction function comprises: identifying groups of pixels in the high dynamic range image for which corresponding pixels in the lower dynamic range image all have the same pixel value within the lower dynamic range image; for each of the plurality of groups, collecting the pixel values of the pixels in the respective group into a respective bin; and determining for each pixel value represented in the lower dynamic range image a predicted pixel value represented in the high dynamic range image based at least in part on the pixel values belonging to each of the bins; apply the prediction function to the lower dynamic range image to obtain a predicted high dynamic range image; compute a residual image representing differences between pixel values in the predicted high dynamic range image and corresponding pixel values in the high dynamic range image; and encode and store data representing the lower dynamic range image, the prediction function and the residual image. obtain a lower dynamic range, LDR, image corresponding to a high dynamic range, HDR, image, the lower dynamic range image being obtainable from the high dynamic range image by a dynamic range reduction process and containing the same scene as the high dynamic range image; generate a prediction function based on the high dynamic range image and the lower dynamic range image, wherein generating the prediction function comprises: identifying groups of pixels in the high dynamic range image for which corresponding pixels in the lower dynamic range image all have the same pixel value within the lower dynamic range image; for each of the plurality of groups, collecting the pixel values of the pixels in the respective group into a respective bin; and determining for each pixel value represented in the lower dynamic range image a predicted pixel value represented in the high dynamic range image based at least in part on the pixel values belonging to each of the bins; identifying groups of pixels in the high dynamic range image for which corresponding pixels in the lower dynamic range image all have the same pixel value within the lower dynamic range image; for each of the plurality of groups, collecting the pixel values of the pixels in the respective group into a respective bin; and determining for each pixel value represented in the lower dynamic range image a predicted pixel value represented in the high dynamic range image based at least in part on the pixel values belonging to each of the bins; apply the prediction function to the lower dynamic range image to obtain a predicted high dynamic range image; compute a residual image representing differences between pixel values in the predicted high dynamic range image and corresponding pixel values in the high dynamic range image; and encode and store data representing the lower dynamic range image, the prediction function and the residual image.