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
#Convolucion | |
im = Image.open("escala.jpg") | |
pix = im.load() | |
dirX = ([-1, 0, 1], [-2, 0, 2], [-1, 0, 1]) | |
dirY = ([1, 2, 1], [0, 0, 0], [-1, -2, -1]) | |
for x in range(0,ancho-3): #Ancho | |
for y in range(0,largo-3): #Largo | |
sumDirX=0 | |
sumDirY=0 | |
for i in range(0,3): | |
for j in range(0,3): | |
sumDirX +=(pix[x+i,y+j][0]*dirX[i][j]) | |
sumDirY +=(pix[x+i,y+j][0]*dirY[i][j]) | |
potX = pow(sumDirX, 2) | |
potY = pow(sumDirY, 2) | |
res = int(math.sqrt(potX+potY)) | |
if res > 255: | |
res = 255 | |
if res < 0: | |
res = 0 | |
pix[x,y] = (res, res, res) | |
im.save("convolucion.jpg") | |
imagen=pygame.image.load("convolucion.jpg") | |
ventana.blit(imagen,(0,0)) | |
pygame.display.update() | |
#Lineas | |
CERO = 0.00001 | |
gx = dirX | |
gy = dirY | |
for x in range(ancho): | |
rhos.append([]) | |
ang.append([]) | |
magn.append([]) | |
for i in range(len(vecinosOrdenados)): # multiplicaciones de matrices | |
gx = (vecinosOrdenados[i] * mascaraX[i]) + gx | |
gy = (vecinosOrdenados[i] * mascaraY[i]) + gy | |
angulo = 0.0 | |
if gx > 0.0 and gy == 0.0: # 0 | |
elegidos.append((indice, rojo)) | |
angulo = 0.0 | |
elif gx < 0.0 and gy == 0.0: # 180 | |
elegidos.append((indice, rojo)) | |
angulo = 180.0 | |
if gx == 0.0 and gy > 0.0: # 90 | |
elegidos.append((indice, azul)) | |
angulo = 90.0 | |
elif gx == 0.0 and gy < 0.0: # 270 | |
elegidos.append((indice, azul)) | |
angulo = 270.0 | |
elif gx * gy != 0.0: # cualquier otro | |
elegidos.append((indice, verde)) | |
angulo = math.atan(gy / gx) | |
im.save("lineas.jpg") | |
imagen=pygame.image.load("lineas.jpg") | |
ventana.blit(imagen,(0,0)) | |
pygame.display.update() |