informatica:programacion:python:modulos:numpy
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:python:modulos:numpy [2020/12/09 15:14] – [Selección] tempwin | informatica:programacion:python:modulos:numpy [2020/12/09 15:59] (actual) – [Métodos] tempwin | ||
|---|---|---|---|
| Línea 51: | Línea 51: | ||
| </ | </ | ||
| + | |||
| + | <WRAP center round tip 60%> | ||
| + | No es necesario indicar el argumento '' | ||
| + | </ | ||
| + | |||
| <WRAP center round info 60%> | <WRAP center round info 60%> | ||
| Línea 190: | Línea 195: | ||
| # Creamos un array de 10 números entre el 0 y el 100 | # Creamos un array de 10 números entre el 0 y el 100 | ||
| arr = np.random.randint(0, | arr = np.random.randint(0, | ||
| + | </ | ||
| + | |||
| + | ===== Imágenes ===== | ||
| + | |||
| + | Por sí mismo, NumPy no es capaz de manejar imágenes sino que se apoya en el módulo PIL (biblioteca pillow, //Python Imaging Library//) | ||
| + | |||
| + | <code python> | ||
| + | import numpy as np | ||
| + | from PIL import Image | ||
| + | |||
| + | # Para poder ver las imágenes en un Notebook de Jupyter | ||
| + | import matplotlib.pyplot as plt | ||
| + | %matplotlib inline | ||
| + | |||
| + | pic = Image.open(' | ||
| + | |||
| + | # Si queremos ver la imagen en Jupyter | ||
| + | pic | ||
| + | |||
| + | type(pic) | ||
| + | |||
| + | # PIL.PngImagePlugin.PngImageFile | ||
| + | </ | ||
| + | |||
| + | Convertimos la imagen a un array de NumPy: | ||
| + | |||
| + | <code python> | ||
| + | pic_arr = np.asarray(pic) | ||
| + | |||
| + | type(pic_array) | ||
| + | |||
| + | # numpy.ndarray | ||
| + | |||
| + | pic_arr.shape | ||
| + | |||
| + | # (1080,1920, 3) | ||
| + | |||
| + | # Mostrar el array como imagen: | ||
| + | plt.imshow(pic_arr) | ||
| + | </ | ||
| + | |||
| + | Para acceder a los canales de color: | ||
| + | |||
| + | <code python> | ||
| + | pic_red = pic_arr.copy() | ||
| + | |||
| + | # R = 0, G = 1, B = 2 | ||
| + | |||
| + | # Canal rojo. 0, sin rojo, negro. 255 puro rojo. | ||
| + | pic_red[:,:, | ||
| + | |||
| + | # Lo representamos como escala de grises, es decir, | ||
| + | # si la imagen se acerca al negro, es que no tendrá presencia de rojo. | ||
| + | # Si se acerca al blanco, tendrá mucha presencia de rojo. | ||
| + | plt.imshow(pic_red[:,:, | ||
| + | |||
| + | # Lo mismo para el verde | ||
| + | plt.imshow(pic_red[:,:, | ||
| + | |||
| + | # Lo mismo para el azul | ||
| + | plt.imshow(pic_red[:,:, | ||
| </ | </ | ||
informatica/programacion/python/modulos/numpy.1607523241.txt.gz · Última modificación: por tempwin
