Page 1 of 1

Programmatically distinguish background gray

Posted: 2017-12-01T09:17:56-07:00
by muccigrosso
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

Re: Programmatically distinguish background gray

Posted: 2017-12-01T10:52:09-07:00
by fmw42
Please always provide your IM version and platform, since syntax may differ. Also post an example image if you can to some free hosting service and put the URL here.

If you are on Unix, then you could try my textcleaner script at my link below. Otherwise, try -lat.

Re: Programmatically distinguish background gray

Posted: 2017-12-01T12:10:26-07:00
by muccigrosso
I'm not a fan of the black/white result of -lat. I was hoping for a more algorithmic way to decide whether or not to do anything.

I'll save the next images this happens with.

Re: Programmatically distinguish background gray

Posted: 2017-12-01T13:04:31-07:00
by fmw42
Try my textcleaner. It can keep your text smooth and the text colors.

Re: Programmatically distinguish background gray

Posted: 2017-12-01T15:09:01-07:00
by muccigrosso
Yep, I know that script. :-)

Part of this is me trying to work with IM.