''' Created on 19 de nov. de 2015 @author: Usuario- Miguel Matey Sanz ''' from moduloimagen import leerImagen, mostrarImagen nombreFichero = input('Introduce el nombre de la imagen: ') matriz = leerImagen(nombreFichero) def reflexion_horizontal(matriz): for i in range(len(matriz)): for j in range(len(matriz[0]) // 2): aux = matriz[i][j] matriz[i][j] = matriz[i][len(matriz[0]) - 1 - j] matriz[i][len(matriz[0]) - 1 - j] = aux return matriz mostrarImagen(reflexion_horizontal(matriz))
if j == len(matriz[0]) - 1 or i == len(matriz) - 1: nova[i][j] = numero def difuminada(matriz, numero): #creem la nova matriu nova = nueva_matriz(len(matriz), len(matriz[0]), 255) #li fique borde borde(matriz, nova, numero) for i in range(len(matriz) - 1): for j in range(len(matriz[0]) - 1): #per a saber que no anem a tocar el marc if i != 0 and j != 0 and j != len( matriz[0]) - 1 and i != len(matriz) - 1: nova[i][j] = round(promedio_entorno(matriz, i, j)) return nova #*************************************************** nombreFichero = input("Introduce el nombre de la imagen: ") matriz = leerImagen(nombreFichero) numero = int(input("Introduce el valor del borde: ")) nou = difuminada(matriz, numero) mostrarImagen(nou)
#autor: Philippe Gonzalez Miralles [24 Novembre] UJI from moduloimagen import leerImagen, mostrarImagen def reflejar_vertical(matriz): fila = len(matriz) columna = len(matriz[fila // 2]) for j in range(columna): for i in range(fila // 2): #matriz[i][j] aux = matriz[len(matriz) - i - 1][j] matriz[len(matriz) - i - 1][j] = matriz[i][j] matriz[i][j] = aux nombreFichero = input("Introduce el nombre de la imagen: ") matriz = leerImagen(nombreFichero) (reflejar_vertical(matriz)) mostrarImagen(matriz)
''' Created on 26 de nov. de 2015 @author: al341802-Miguel Matey Sanz ''' from moduloimagen import leerImagen, mostrarImagen def girar_derecha(matriz): matriz_nueva = crear_matriz(len(matriz[0]), len(matriz), 0) for fila in range(len(matriz)): for col in range(len(matriz[0])): matriz_nueva[col][fila] = matriz[-fila - 1][col] return matriz_nueva def crear_matriz(filas, columnas, n): matriz = [] for i in range(filas): matriz.append([n] * columnas) return matriz nombreFichero = input('Introduce el nombre de la imagen: ') matriz = leerImagen(nombreFichero) mostrarImagen(girar_derecha(matriz))
@author: Usuario- Miguel Matey Sanz ''' from moduloimagen import leerImagen, mostrarImagen nombreFichero = input('Introduce el nombre de la imagen: ') matriz = leerImagen(nombreFichero) def crear_matriz(filas, columnas, n): matriz = [] for i in range(filas): matriz.append([n] * columnas) return matriz def binarizar_imagen(matriz, umbral): matriz_nueva = crear_matriz(len(matriz), len(matriz[0]), 0) for i in range(len(matriz)): for j in range(len(matriz[0])): if matriz[i][j] > umbral: matriz_nueva[i][j] = 255 return matriz_nueva umbral = int(input('Introduce el umbral: ')) mostrarImagen(binarizar_imagen(matriz, umbral))
''' Created on 26 de nov. de 2015 @author: al341802-Miguel Matey Sanz ''' from moduloimagen import leerImagen, mostrarImagen def reflexion_vertical(matriz): for col in range(len(matriz[0])): for fila in range(len(matriz)//2): aux=matriz[fila][col] matriz[fila][col]=matriz[len(matriz)-1-fila][col] matriz[len(matriz)-1-fila][col]=aux return matriz nombreFichero=input('Introduce el nombre de la imagen: ') matriz=leerImagen(nombreFichero) mostrarImagen(reflexion_vertical(matriz))
from moduloimagen import leerImagen, mostrarImagen def binarizada(matriz,umbral): matriz2=nueva_matriz(len(matriz),len(matriz[0]),0) for i in range(len(matriz)): for j in range(len(matriz[0])): if matriz[i][j]<=umbral: matriz2[i][j]=0 else: matriz2[i][j]=255 return matriz2 def nueva_matriz(nFila,nColumna,valor): matriz = [valor] * nFila for i in range(nFila): matriz[i] = [valor] * nColumna return matriz nombreFichero = input("Introduce el nombre de la imagen: ") umbral=int(input("Introduce el umbral: ")) matriz = leerImagen(nombreFichero) binar=binarizada(matriz,umbral) mostrarImagen(binar) #print(matriz)
def difuminar_imagen(matriz, borde): matriz_nueva=crear_matriz(len(matriz),len(matriz[0]), borde) for fila in range(1,len(matriz)-1): for col in range(1,len(matriz[0])-1): matriz_nueva[fila][col]=round(promediar_punto(matriz,fila,col)) return matriz_nueva def promediar_punto(matriz, n_fila, n_col): sumatorio=0 fila=n_fila-1 #Calculamos la primera fila de nuesta matriz 3x3 col=n_col-1 #Calculamos la primera columna de nuestra matriz 3x3 for i in range(fila,fila+3): for j in range(col, col+3): sumatorio+=matriz[i][j] return sumatorio/9 def crear_matriz(filas,columnas,n): matriz=[] for i in range(filas): matriz.append([n]*columnas) return matriz nombreFichero=input('Introduce el nombre de la imagen: ') matriz=leerImagen(nombreFichero) borde=int(input('Introduce el valor del borde: ')) mostrarImagen(difuminar_imagen(matriz,borde))