A compression method for compressing an inputted digital image of a scanned document, said compression method comprising the steps of: - segmenting said inputted digital image into multiple image layers comprising a foreground image containing color information for foreground elements of said document, a background image containing color information for background elements of said document and a binary mask image for selecting between pixels in said foreground image and said background image upon decompressing said compressed digital image, and - compressing (300, 400, 500) each of the image layers by means of a suitable compression technique, thereby obtaining a compressed digital image, wherein the binary mask image is created by a method comprising the steps of: a) creating a binarized image by binarizing the inputted digital image, b) processing (130; 140) said binarized image to create a transformed binary image (138; 157), and c) generating the binary mask image from the transformed binary image (138; 157), characterized in that step b) comprises the steps of: - creating (131; 143) a first image by keeping only first black blobs having a number of pixels above a given minimum in the binarized image, - inverting (132; 144) the first image to create a second image, - combining (133; 145) with a logical AND the binarized image with the second image to form a third image, - creating (134; 149) a fourth image by keeping only second black blobs having a number of pixels above a given minimum in the second image, - inverting (135; 150) the fourth image to create a fifth image, - combining (136; 151) with a logical AND the fifth image with the second image to create a sixth image, and - combining (137; 152) with a logical XOR the third image with the sixth image to form the transformed binary image (138; 157), and in that step c) comprises eliminating blobs relating to no actual text elements and keeping blobs relating to text elements by a filtering step that uses the Minimum Description Length Principle, the filtering including, for each blob, the steps of: - estimating a background cost in case the blob is compressed as being part of the background, - estimating a foreground cost in case the blob is compressed as being part of the foreground, and - filtering the blob if: background cost < foreground cost + perimeter * factor, the background cost being a sum of errors between the colors of the pixels of the blob and a local average color, wherein the background cost estimation assumes that colors change smoothly, the foreground cost being a sum of errors between the colors of the pixels of the blob and an average color of the blob, wherein the foreground cost estimation assumes that all the pixels of the blob have the same color, and the factor being a tunable parameter. - segmenting said inputted digital image into multiple image layers comprising a foreground image containing color information for foreground elements of said document, a background image containing color information for background elements of said document and a binary mask image for selecting between pixels in said foreground image and said background image upon decompressing said compressed digital image, and - compressing (300, 400, 500) each of the image layers by means of a suitable compression technique, thereby obtaining a compressed digital image, a) creating a binarized image by binarizing the inputted digital image, b) processing (130; 140) said binarized image to create a transformed binary image (138; 157), and c) generating the binary mask image from the transformed binary image (138; 157), - creating (131; 143) a first image by keeping only first black blobs having a number of pixels above a given minimum in the binarized image, - inverting (132; 144) the first image to create a second image, - combining (133; 145) with a logical AND the binarized image with the second image to form a third image, - creating (134; 149) a fourth image by keeping only second black blobs having a number of pixels above a given minimum in the second image, - inverting (135; 150) the fourth image to create a fifth image, - combining (136; 151) with a logical AND the fifth image with the second image to create a sixth image, and - combining (137; 152) with a logical XOR the third image with the sixth image to form the transformed binary image (138; 157), and in that step c) comprises eliminating blobs relating to no actual text elements and keeping blobs relating to text elements by a filtering step that uses the Minimum Description Length Principle, the filtering including, for each blob, the steps of: - estimating a background cost in case the blob is compressed as being part of the background, - estimating a foreground cost in case the blob is compressed as being part of the foreground, and - filtering the blob if: background cost < foreground cost + perimeter * factor, the background cost being a sum of errors between the colors of the pixels of the blob and a local average color, wherein the background cost estimation assumes that colors change smoothly, the foreground cost being a sum of errors between the colors of the pixels of the blob and an average color of the blob, wherein the foreground cost estimation assumes that all the pixels of the blob have the same color, and the factor being a tunable parameter.