Created
February 18, 2013 22:16
-
-
Save vane90/4981271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bfs(image,color,a,b): | |
imagen=image.load() | |
ancho,alto=image.size | |
original = imagen[a,b] | |
c=[] | |
xs=[] | |
ys=[] | |
c.append((a,b)) | |
n = 0 | |
while len(c) > 0: | |
(x, y) = c.pop(0) | |
actual = imagen[x, y] | |
if actual == original or actual == color: | |
for dx in [-1, 0, 1]: | |
for dy in [-1, 0, 1]: | |
i, j = (x + dy, y + dx) | |
if i >= 0 and i < ancho and j >= 0 and j < alto: | |
contiene = imagen[i, j] | |
if contiene == original: | |
imagen[i, j] = color | |
xs.append(i) | |
ys.append(j) | |
n += 1 | |
c.append((i, j)) | |
forma1 = image.save('formas.png') | |
return n, xs, ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment