I'm trying to create a captcha solver for a site using python, but i'm not able to remove extra pixels (those with no other pixels around it)
i've managed to get really close, removing almost every extra pixel, but my code works only once, and then it stops having any effect on the image.
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
from operator import itemgetter
import PIL.ImageOps
for x in range(im2.size[1]):
for y in range(im2.size[0]):
pix = im2.getpixel((y,x))
im2.putpixel((0,21), (0,0,0))
if pix < 180:
try:
left = im2.getpixel((y-1,x))
except IndexError:
left = 255
pass
try:
right = im2.getpixel((y+1,x))
except IndexError:
right = 255
pass
try:
up = im2.getpixel((y,x-1))
except IndexError:
up = 255
pass
try:
down = im2.getpixel((y,x+1))
except IndexError:
down = 255
pass
if (left == 255 and right == 255) or (up == 255 and down == 255):
im2.putpixel((y,x),(255,255,255))
i would like to remove any pixels with no other pixels either on the side or up and down.
import
statements so we can't see which libraries you are using or run your code? If you want folks to help you, it's generally a good idea to make it easy for them... ;-)