Created
February 12, 2013 12:02
-
-
Save AdriC1705/4761877 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 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