Scanned document filtering

I am trying to filter images filtered for a document scanner app.
By that i mean simplifying colors.
There is android scanner app which does something i really like and i am trying to reverse engineer it. It has nice result in turning the image to “black and white” (actually gray image as it is not binary) and still preserve primary color zones.
Would someone have an idea on how you could get such a result?