Вот
Language:
Python3
Editor:
PyCharm 4.5.2
Code:
import random
from PIL import Image, ImageDraw
for i in range(5):
im = Image.open("fcap/70/"+str(i)+".jpg").convert("RGB")
draw = ImageDraw.Draw(im)
img = im.load()
white = (255, 255, 255)
black = (0, 0, 0)
for x in range(im.size[0]):
for y in range(im.size[1]):
px = im.getpixel((x,y))
#в следующей строке выдает ошибку
if (img[x, y] == black and img[x+1, y]==white and img[x-1, y]==white and img[x, y+1]==white and img[x, y-1]==white):
if(img[x+1, y+1]==white and img[x+1, y-1]==white and img[x-1, y+1]==white and img[x-1, y-1]==white):
img[x, y] = white
elif (px != black and px != white and px[0] > 19 and px[1] > 19 and px[2] > 19):
img[x, y] = white
else:
img[x, y] = black
im.save("fcap/"+str(i)+".jpg")
del draw