How to equalize background illumination?
Posted: 2015-10-06T11:20:46-07:00
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.)
This allows us to go from this:
to this:
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?
(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:
to this:
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?