/
Bordes.py
80 lines (56 loc) · 1.92 KB
/
Bordes.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
#import the necessary packages
from sklearn.cluster import KMeans
import time
import matplotlib.pyplot as plt
import numpy as np
from SimpleCV import Image,Camera,Display,Image,Color
img=Image("lunarr2.jpg")#importamos la imagen a la cual deseamos determinarle los bordes
foto=img.show()
#imagen en escala de grises
imgGray=img.grayscale()
imgGray.save("grayLab2.png")
hist=imgGray.histogram(255)
plt.figure(1)
plt.plot(hist)
plt.savefig("histogray.png")
#imagen en escala RGB
(red,green,blue)=img.splitChannels(False)
#Histograma imagen RGB
red_histogram=red.histogram(255)
plt.figure(2)
plt.plot(red_histogram)
plt.savefig("histogred.png")
green_histogram=green.histogram(255)
plt.figure(3)
plt.plot(green_histogram)
plt.savefig("histogreen.png")
blue_histogram=blue.histogram(255)
plt.figure(4)
plt.plot(blue_histogram)
plt.savefig("histoblue.png")
#se guardan la imagen RGB
red.save("imagen_r.png")
green.save("imagen_g.png")
blue.save("imagen_b.png")
imgb=imgGray.binarize(50) #dependiendo de la oscuridad de la imagen se modifica
imgb.save("bingray.png")
#estimación del gradiente
bingrad=imgb.morphGradient().save("bingradiennre.png")# determinamos el gradiente de la imagen binarizada, lo que nos da los bordes.
fda=imgb.morphGradient()
fotobordesgrad=fda.show()
graygrad=imgGray.morphGradient().save("Graygradiennre.png")
REDgrad=red.morphGradient().save("redgradiente.png")
GREENgrad=green.morphGradient().save("greengradiente.png")
BLUEgrad=blue.morphGradient().save("bluegradiente.png")
imgbinsobel = imgb.sobel().save("binsobel.png")
sbl=imgb.sobel()
imgGraysobel = imgGray.sobel().save("GRAYsobel.png")
red_edgesobel = red.sobel().save("REDsobel.png")
green_edgesobel = green.sobel().save("GREENsobel.png")
blue_edgesobel = blue.sobel().save("BLUEsobel.jpg")
imagenfin= fda + img
imagenfin.save("BordesGrad.png")
fotobordesfinal=imagenfin.show()
imagenfin2= sbl+img
imagenfin.save("BordesSobel.png")