Decompose an image into better compressible components
Assuming that the image is gray level (not color)


Use Otsu's thresholding method to detect whether the image has bi-modal histogram.
If Otsu tells you with high confidence that the image is bi-modal, use the threshold that it gave you in order to binarize the image. That is your binary mask that can be effectively packed into bits.
Find the gray values of the two histogram modes, create a mask where the "white" color is the gray value of the second mode and "black" color is the value of the first mode.
Subtract previously made mask from the image. These are your small changes that you can compress by using lossy compression.
Save the two modes as two integers together with the document.