(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?