data = image.load()
for y in range(height):
    for x in range(width):
        if data[x, y] > 128:
            continue
total = 0
for c in range(x, width):
    if data[c, y] < 128:
        total += 1
else:
    break
if total <= chop:
    for c in range(total):
        data[x + c, y] = 255
x += total
for x in range(width):
    for y in range(height):
        if data[x, y] > 128:
            continue
total = 0
for c in range(y, height):
    if data[x, c] < 128:
        total += 1
else:
    break
if total <= chop:
    for c in range(total):
        data[x, y + c] = 255
y += total
image.save(sys.argv[3])
Removing the background noise of a captcha image by replicating the chopping filter of TesserCap