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
Programmatically distinguish background gray
-
- Posts: 64
- Joined: 2017-10-03T10:39:52-07:00
- Authentication code: 1151
Programmatically distinguish background gray
Last edited by muccigrosso on 2017-12-01T11:43:40-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Programmatically distinguish background gray
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.
If you are on Unix, then you could try my textcleaner script at my link below. Otherwise, try -lat.
-
- Posts: 64
- Joined: 2017-10-03T10:39:52-07:00
- Authentication code: 1151
Re: Programmatically distinguish background gray
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.
I'll save the next images this happens with.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Programmatically distinguish background gray
Try my textcleaner. It can keep your text smooth and the text colors.
-
- Posts: 64
- Joined: 2017-10-03T10:39:52-07:00
- Authentication code: 1151
Re: Programmatically distinguish background gray
Yep, I know that script.
Part of this is me trying to work with IM.
Part of this is me trying to work with IM.