viernes, 6 de septiembre de 2024

CE3.2 Ejemplo de Operaciones Matemáticas en Imágenes, INSTALAR TAMBIÉN LA biblioteca NumPy Y TAMBIEN Pillow (PIL)

¡¡¡Ojo!!! Instalar estas bibliotecas


pip install numpy

pip install pillow

pip install opencv-python matplotlib






import numpy as np

from PIL import Image

import matplotlib.pyplot as plt


# Cargar imagen y convertir a array NumPy

image = Image.open('ruta_a_tu_imagen.jpg')

image_array = np.array(image)


# Aplicar una operación matemática (aumentar brillo)

bright_image_array = image_array + 50

bright_image_array = np.clip(bright_image_array, 0, 255).astype(np.uint8)


# Convertir array de nuevo a imagen

bright_image = Image.fromarray(bright_image_array)


# Mostrar imagen original y con mayor brillo

plt.subplot(1, 2, 1)

plt.title('Original')

plt.imshow(image)


plt.subplot(1, 2, 2)

plt.title('Brillo Aumentado')

plt.imshow(bright_image)


plt.show()


RESULTADO:

Aplicación.py  de nuevo con el nombre de la imagen:


import numpy as np

from PIL import Image

import matplotlib.pyplot as plt


# Cargar imagen y convertir a array NumPy

image = Image.open('floree.jpg')

image_array = np.array(image)


# Aplicar una operación matemática (aumentar brillo)

bright_image_array = image_array + 50

bright_image_array = np.clip(bright_image_array, 0, 255).astype(np.uint8)


# Convertir array de nuevo a imagen

bright_image = Image.fromarray(bright_image_array)


# Mostrar imagen original y con mayor brillo

plt.subplot(1, 2, 1)

plt.title('Original')

plt.imshow(image)


plt.subplot(1, 2, 2)

plt.title('Brillo Aumentado')

plt.imshow(bright_image)


plt.show()


https://learnpython.org/ walter tan bueno como w3schools

 T an bueno como w3schools   https://learnpython.org/  apuntes python 3 con ejercicios  Walter En w3schools hay  html y css también, muy bue...