A method for encoding a first image of which pixel values have a first bit depth, comprising: obtaining a second image that corresponds to the first image, wherein pixel values of the second image have a second bit depth lower than the first bit depth; encoding the second image using a second encoder ; predicting the first image based on the second image; calculating a non-quantized residual image based on a difference between the predicted first image and the first image, wherein pixel values of the non-quantized residual image have a bit depth which is one bit more than the first bit depth to distinguish positive and negative pixel values; grouping pixels in the non-quantized residual image into a plurality of pixel groups, wherein said grouping comprises: for each pixel in the residual image, comparing the pixel value of the corresponding pixel in the second image, in the decoded encoded second image, or in the predicted first image, to a plurality of pixel value ranges respectively corresponding to the plurality of pixel groups and assigning said each pixel to a given pixel group among said plurality pixel groups if the pixel value of its corresponding pixel falls in the range attributed to that pixel group; quantizing the pixels in each respective pixel group by applying a respective quantizing function to the pixels in each respective pixel group, wherein the bit depth of pixel values in the quantized residual image is smaller than the bit depth of pixel values in the non-quantized residual image, wherein each quantizing function maps each pixel value of the pixels in a given pixel group to a corresponding value within a range of pixel values that is defined by the bit depth of pixel values in the quantized residual image; and encoding the quantized residual image using a first encoder . obtaining a second image that corresponds to the first image, wherein pixel values of the second image have a second bit depth lower than the first bit depth; encoding the second image using a second encoder ; predicting the first image based on the second image; calculating a non-quantized residual image based on a difference between the predicted first image and the first image, wherein pixel values of the non-quantized residual image have a bit depth which is one bit more than the first bit depth to distinguish positive and negative pixel values; grouping pixels in the non-quantized residual image into a plurality of pixel groups, wherein said grouping comprises: for each pixel in the residual image, comparing the pixel value of the corresponding pixel in the second image, in the decoded encoded second image, or in the predicted first image, to a plurality of pixel value ranges respectively corresponding to the plurality of pixel groups and assigning said each pixel to a given pixel group among said plurality pixel groups if the pixel value of its corresponding pixel falls in the range attributed to that pixel group; quantizing the pixels in each respective pixel group by applying a respective quantizing function to the pixels in each respective pixel group, wherein the bit depth of pixel values in the quantized residual image is smaller than the bit depth of pixel values in the non-quantized residual image, wherein each quantizing function maps each pixel value of the pixels in a given pixel group to a corresponding value within a range of pixel values that is defined by the bit depth of pixel values in the quantized residual image; and encoding the quantized residual image using a first encoder . <EOS>