Page 1 of 1

How to equalize background illumination?

Posted: 2015-10-06T11:20:46-07:00
by nicolai.rostov
I've found what seems a very effective method here http://stackoverflow.com/a/4632685 to remove (or equalize, I'm not sure what technical term to use) background illumination from photographs of drawings or manuscripts, in order to arrive at a clean black-and-white image of that drawing by means of a simple threshold.

(The assumption here is that simply adjusting brightness and contrast will not do because of shadows, etc.)

Code: Select all

from PIL import Image
from PIL import ImageFilter
im = Image.open(r'c:\temp\temp.png')
white = im.filter(ImageFilter.BLUR).filter(ImageFilter.MaxFilter(15))

grey = im.convert('L')
width,height = im.size
impix = im.load()
whitepix = white.load()
greypix = grey.load()
for y in range(height):
    for x in range(width):
        greypix[x,y] = min(255, max(255 + impix[x,y][0] - whitepix[x,y][0], 255 + impix[x,y][7] - whitepix[x,y][8], 255 + impix[x,y][9] - whitepix[x,y][10]))

This allows us to go from this:
Image

to this:
Image

However, I don't know how to use the Python interface the author of the answer is using. Is it possible to achieve the same result using the convert tool from the command line? How?

Re: How to equalize background illumination?

Posted: 2015-10-06T12:07:28-07:00
by Bonzo
fmw42 has a script you may be able to use: whiteboard

Re: How to equalize background illumination?

Posted: 2015-10-06T14:21:34-07:00
by nicolai.rostov
Excellent. Thank you.

Re: How to equalize background illumination?

Posted: 2015-10-06T15:39:10-07:00
by fmw42
Besides my script whiteboard and textcleaner, see the IM function -lat. see http://www.imagemagick.org/script/comma ... ns.php#lat