Skip to content

Instantly share code, notes, and snippets.

@alejandroave
Created May 29, 2013 00:38
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 alejandroave/5667194 to your computer and use it in GitHub Desktop.
Save alejandroave/5667194 to your computer and use it in GitHub Desktop.
def proces(imagen):
escala(imagen) ##transformamos imagen a gris
ancho,altura,pixels,im = cargar("gris.jpg") ##cargamos imagen a gris
i = 0
j = 0
print "valor de altura: ",altura
arreglo = []
#for i in range(altura):
# arreglo.append([])
# for j in range(ancho):
# arreglo[i].append(0)
i = 0
j = 0
while i < altura: ##recorre la imagen
#arreglo.append([])
while j < ancho:
if ancho - j >= 8 and altura - i >= 8:
mat = []
#ash = 0
for k in range(8): ##bloques de ocho
mat.append([])
for l in range(8):
#ash += 1
mat[k].append(pixels[l+j,k+i][0]) ##vamos guardando la matriz
#print mat
mat = temmat(mat) ##pasamos la matriz en formato de numpy
mat = trans(mat) ##hacemos la transformada y la cuantificacion
#sumc = mat[0][0]
conts = 0
array = []
#print mat
for k in range(8):
for l in range(8):
if mat[k][l] != 0 and abs(mat[k][l]) < 1: ##umbralisamos y modificamos
mat[k][l] = 0.0 #3la matriz cuantificada
#print mat[k][l]
#array.append(pixels[j+l,i+k][0])
#conts += 1
finaly = regr(mat) ##aplicamos inverso de dct
#print finaly
#print finaly
for k in range(8): ##pintamos nuevamente
for l in range(8):
pixels[j+l,i+k] = (int(finaly[k][l]),int(finaly[k][l]),int(finaly[k][l]))
#if conts > 4: ##otro metodo diferente
# array.sort()
# num = len(array)/2
# pix = array[int(num)]
# for k in range(8):
# for l in range(8):
# pixels[j+l,i+k] = (pix,pix,pix)
j = j + 8
else:
j = j + 1
#print j
i = i + 8
#print i
j = 0
im.save("finall.jpeg")
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment