-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicExercise 26.py
More file actions
57 lines (33 loc) · 1.1 KB
/
BasicExercise 26.py
File metadata and controls
57 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python2.6
#_*_coding:utf8_*_
#Ser importan las librerias PIL
from PIL import Image
# Se importa la libreri numerica para tratar con la matriz de RGB
import numpy as np
#Importar imagen
img= Image.open("/home/rpetit/Python/figura.jpg.eps")
print img.mode
# Para cponvertir la imangen a RBJ
img2=img.convert("RGB")
#Para usar una matris
ro,ve,az=img2.split()
#Se convierte la barra ro en un arreglo
datos_ro=np.array(ro.getdata())
print type(datos_ro)
print datos_ro.size
print datos_ro.shape
print datos_ro
print ro
#Formando la matriz original (dimenciones en x=213 y en y=159)
print img2.size
datos_ro_matriz= datos_ro.reshape(159,213)
#Confirmacion de dtos
print datos_ro_matriz.size
# Para poder trabajar con las matrices de guardan las dimensiones en una variable
(x,y)=datos_ro_matriz.shape
datos_ro_matriz[: , (y/2)-20:(y/2)+20]=122*np.ones((x,40))
# Se forma un nuevo vectotor para convertir la banda ro para convertirla en un vector del tamano delas x y y
nuevo_ro= datos_ro_matriz.reshape(x*y)
ro.putdata(nuevo_ro)
nueva_img2=Image.merge("RGB",(ro,ve,az))
nueva_img2.show()