normalizing B&W doc with different contrast

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tmuna
Posts: 1
Joined: 2017-04-24T06:19:16-07:00
Authentication code: 1151

normalizing B&W doc with different contrast

Post by tmuna »

The documents has different brightness regions.

Is there a simple command that will intensify each contrast area to B&W ?
Like the HDR, that can "pull out" details in dark areas;

then the desired result :
Since the document is essentially Black and white (text), the final result should have maximum contrast,
Maximum 4 to 8 colors.

original image:
Image

process by a program called "PageLift"; I couldn't find how it works:
Image

I tried:
-gamma : values 2.0 - 4.0. The image was relatively balanced, but still dark, contrast was low;
-evaluate pow (this is essentially the same)
-log 100 (relatively good results, i don't know how to explain its significance in words)
-level 50 - similar to the gamma results, but more blur
-modul120-90 : different regions differ for each other
-sigmoid - blurry and inconsistent

here's the gamma 3 result:
Image

I have intermediate experiene in ImageMagick.
I couldn't find "HDR Effect" - if such exists.

If possible,
I'd like to get pointers to either options, or scripts,
or (if possible :) ) relevant terminology so I can understand it.

imagemagick 7.0.5
windows 7 via console (CMD)
I can also use bash

__________
*i'd use PageLift for all documents, but it doesn't have command line interface...
Last edited by tmuna on 2017-04-25T00:40:07-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: normalizing B&W doc with different contrast

Post by snibgo »

What version of IM? What platform?

There are many methods. Dividing by a blur is often a good start, eg (IM v6, Windows CMD syntax):

Code: Select all

convert ifbn2q.png ( +clone -blur 0x10 ) -compose DivideSrc -composite out.png
Then you can adjust the contrast, reduce to grayscale, reduce the number of colours etc.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normalizing B&W doc with different contrast

Post by fmw42 »

If you are on a unix-like platform, then try my script, text cleaner, at the link below. If on Windows, my script will not work, but try -lat. See http://www.imagemagick.org/script/comma ... ns.php#lat. Something like -lat 25x25+10%. Adjust the 25x25 as desired.
Post Reply