Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def filtro(img,ancho,alto):
tiemp= time()
pixel =img.load()
for i in range (ancho):
for j in range(alto):
c = 0
prom = 0.0
try:
if(pixel[i+1,j]):
prom += pixel[i+1,j][0]
c +=1
except:
prom += 0
try:
if(pixel[i-1,j]):
prom += pixel[i-1,j][0]
c +=1
except:
prom += 0
try:
if(pixel[i,j+1]):
prom += pixel[i,j+1][0]
c+=1
except:
prom += 0
try:
if(pixel[i,j-1]):
prom += pixel[i,j-1][0]
c+=1
except:
prom += 0
promt = int(prom/c)
pixel[i,j] = (promt, promt, promt)
im=img.save ('filtro.jpg')
timei=time()
timef= timei - tiemp
print "Tiempo de ejecucion del filtro: "+str(timef)+"segundos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment