Skip to content

Instantly share code, notes, and snippets.

@AdriC1705
Created February 12, 2013 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdriC1705/4761877 to your computer and use it in GitHub Desktop.
Save AdriC1705/4761877 to your computer and use it in GitHub Desktop.
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