Programmatically distinguish background gray
Posted: 2017-12-01T09:17:56-07:00
I'm using IM to clean up some scanned grayscale pages from a text. Right now I clean up the background when there's some poor scanning artifacts like shadows near a book spine by doing a contrast stretch of 5%,90%. This works well _except_ when the page doesn't really need the cleanup. Then the stretch darkens pixels around the letters, widening them.
If I look at the histograms, I can see that the "dirty" images have a noticeable shoulder near white (as you'd expect), while the "clean" images don't. So what would be the best way to use this to turn on or off the contrast stretch? Do I need to process the histogram data or is there some built-in function that will work?
TIA.
EDIT: ImageMagick 7.0.7-12 Q16 x86_64 2017-11-30 on MacOS 10.11.6
If I look at the histograms, I can see that the "dirty" images have a noticeable shoulder near white (as you'd expect), while the "clean" images don't. So what would be the best way to use this to turn on or off the contrast stretch? Do I need to process the histogram data or is there some built-in function that will work?
TIA.
EDIT: ImageMagick 7.0.7-12 Q16 x86_64 2017-11-30 on MacOS 10.11.6