Skip to content

Instantly share code, notes, and snippets.

@pepgonzalez
Created February 3, 2013 23:50
Show Gist options
  • Save pepgonzalez/4704263 to your computer and use it in GitHub Desktop.
Save pepgonzalez/4704263 to your computer and use it in GitHub Desktop.
from PIL import Image
import numpy as n
from datetime import *
import sys
import math
def filtroGrisesPromedio(px):
for i in xrange(0,px.shape[0]):
for j in xrange(0,px.shape[1]):
e = px[i][j]
n1 = (int(e[0])+int(e[1])+int(e[2])) / 3
px[i][j] = [n1,n1,n1]
img = Image.fromarray(px, 'RGB')
img.show()
def filtroGrisesLigero(px):
for i in xrange(0,px.shape[0]):
for j in xrange(0,px.shape[1]):
e = px[i][j]
n1 = (int(max(e)) + int(min(e))) / 2
px[i][j] = [n1,n1,n1]
img = Image.fromarray(px, 'RGB')
img.show()
def porcentajeInfluencia(d):
res = math.e**(-((d)**2))
print res
def filtroVecino(px,px2):
for i in xrange(0,px.shape[0]):
c = 0
for j in xrange(0,px.shape[1]):
r,g,b = px[i][j]
try:
r += int(px[i+1][j][0])
g += int(px[i+1][j][1])
b += int(px[i+1][j][2])
c +=1
except:
None
try:
r += int(px[i-1][j][0])
g += int(px[i-1][j][1])
b += int(px[i-1][j][2])
c +=1
except:
None
try:
r += int(px[i][j+1][0])
g += int(px[i][j+1][1])
b += int(px[i][j+1][2])
c +=1
except:
None
try:
r += int(px[i][j-1][0])
g += int(px[i][j-1][1])
b += int(px[i][j-1][2])
c +=1
except:
None
pr = r / c
pg = g / c
pb = b / c
px2[i][j] = [pr,pg,pb]
c = 1
img = Image.fromarray(px2, 'RGB')
img.show()
print "inicio ejecucion: %s"%(datetime.today())
imagen = Image.open(sys.argv[1])
px = n.array(imagen)
im2 = imagen.copy()
px2 = n.array(im2)
radio = int(sys.argv[2])
filtroGrisesPromedio(px)
#filtroGrisesLigero(px)
filtroVecino(px,px2)
print "final ejecucion: %s"%(datetime.today())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment