1. A computer system for compressing a document, the computer system comprising one or more processors, one or more computer-readable memories, and one or more computer-readable storage devices, and program instructions stored on at least one of the one or more storage devices for execution by at least one of the one or more processors via at least one of the one or more memories, the stored program instructions comprising: program instructions to count a number of edges present in a selected portion of the document; program instructions to determine whether the number of edges exceeds a threshold number of edges; program instructions to select, responsive to the number of edges exceeding the threshold number of edges, a pixel from the portion; program instructions to identify, for the pixel, a set of neighboring pixels; program instructions to identify, for each neighboring pixel in a subset of the set of neighboring pixels, a corresponding label of the neighboring pixel, wherein a mask layer corresponding to the document contains labels of pixels in the portion; program instructions to bias, in the mask layer, a label of the selected pixel using labels of neighboring pixels in the subset of the neighboring pixels; program instructions to designate, according to the label of the selected pixel, the selected pixel to one of a foreground layer corresponding to the document and a background layer corresponding to the document; and program instructions to construct, corresponding to the document, a compressed document using the mask layer, the foreground layer, and the background layer.