Skip to content

Instantly share code, notes, and snippets.

@AdriC1705
Created February 14, 2013 03:30
Show Gist options
  • Save AdriC1705/4950405 to your computer and use it in GitHub Desktop.
Save AdriC1705/4950405 to your computer and use it in GitHub Desktop.
def ruido(img2, ancho,alto):
t1 = time()
pixel= img2.load()
for i in range(ancho):
for j in range(alto):
(r,g,b)= img2.getpixel((i,j)) #obtener pixeles
ruido = random.randint(0,255) #generar ruido random
z = random.randint(0,5000)
try:
if (ruido < 100):
pixel[i+z,j+z]=(0,0,0) #pixel leido mas un numero random para agregar pimienta
else:
pixel[i+z,j+z] = (255,255,255) #pixel + # rand para agregar sal
except:
pass
img2 = img2.save('ruido.jpg')
timei=time()
timef = timei - t1
print "el tiempo para agregar ruido es:"+str(timef)+"segundos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment