-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_gray_level.py
160 lines (122 loc) · 3.66 KB
/
binary_gray_level.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
# Import library
import numpy as np
from skimage.io import imread
from skimage import morphology
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
from skimage.morphology import disk
file_name = './Dataset/13291732978427.jpg'
folha = imread(file_name)
folha = rgb2gray(folha)
folha = folha.max() - folha
radios = 5
dilat = morphology.dilation(folha, disk(radios))
eros = morphology.erosion(folha, disk(radios))
""" fig = plt.figure(figsize=(10,10))
a = fig.add_subplot(1,4,1)
plt.imshow(folha, cmap=plt.get_cmap('gray'))
a.set_title('Original')
plt.axis('off')
a = fig.add_subplot(1,4,2)
plt.imshow(dilat, cmap=plt.get_cmap('gray'))
a.set_title('Dilatação')
plt.axis('off')
a = fig.add_subplot(1,4,3)
plt.imshow(eros, cmap=plt.get_cmap('gray'))
a.set_title('Erosão')
plt.axis('off')
a = fig.add_subplot(1,4,4)
plt.imshow(disk(radios), cmap=plt.get_cmap('gray'))
a.set_title('E. Estrut.')
plt.axis('off')
plt.tight_layout()
plt.show() """
cont_ext = morphology.dilation(folha, disk(radios)) - folha
cont_int = folha - morphology.erosion(folha, disk(radios))
cont = morphology.dilation(folha, disk(radios)) - morphology.erosion(folha, disk(radios))
""" fig = plt.figure(figsize=(100,100))
a = fig.add_subplot(1,3,1)
plt.imshow(cont_ext, cmap=plt.get_cmap('gray'))
a.set_title('Contorno Ext.')
plt.axis('off')
a = fig.add_subplot(1,3,2)
plt.imshow(cont_int, cmap=plt.get_cmap('gray'))
a.set_title('Contorno Int.')
plt.axis('off')
a = fig.add_subplot(1,3,3)
plt.imshow(cont, cmap=plt.get_cmap('gray'))
a.set_title('Contorno ')
plt.axis('off')
plt.tight_layout()
plt.show() """
eros_3 = morphology.erosion(folha, disk(3))
eros_15 = morphology.erosion(folha, disk(15))
eros_30 = morphology.erosion(folha, disk(30))
""" fig = plt.figure(figsize=(100,100))
a = fig.add_subplot(1,3,1)
plt.imshow(eros_3, cmap=plt.get_cmap('gray'))
a.set_title('Erosão (3)')
plt.axis('off')
a = fig.add_subplot(1,3,2)
plt.imshow(eros_15, cmap=plt.get_cmap('gray'))
a.set_title('Erosão (15)')
plt.axis('off')
a = fig.add_subplot(1,3,3)
plt.imshow(eros_30, cmap=plt.get_cmap('gray'))
a.set_title('Erosão (30)')
plt.axis('off')
plt.tight_layout()
plt.show() """
open_3 = morphology.opening(folha, disk(3))
open_15 = morphology.opening(folha, disk(15))
open_30 = morphology.opening(folha, disk(30))
""" fig = plt.figure(figsize=(100,100))
a = fig.add_subplot(1,4,1)
plt.imshow(folha, cmap=plt.get_cmap('gray'))
a.set_title('Original')
plt.axis('off')
a = fig.add_subplot(1,4,2)
plt.imshow(open_3, cmap=plt.get_cmap('gray'))
a.set_title('Abert (3)')
plt.axis('off')
a = fig.add_subplot(1,4,3)
plt.imshow(open_15, cmap=plt.get_cmap('gray'))
a.set_title('Abert (15)')
plt.axis('off')
a = fig.add_subplot(1,4,4)
plt.imshow(open_30, cmap=plt.get_cmap('gray'))
a.set_title('Abert (30)')
plt.axis('off')
plt.tight_layout()
plt.show() """
dif_3 = folha - open_3
dif_15 = folha - open_15
dif_30 = folha - open_30
""" fig = plt.figure(figsize=(100,100))
a = fig.add_subplot(1,4,1)
plt.imshow(dif_3, cmap=plt.get_cmap('gray'))
a.set_title('Original')
plt.axis('off')
a = fig.add_subplot(1,4,2)
plt.imshow(dif_15, cmap=plt.get_cmap('gray'))
a.set_title('Abert (3)')
plt.axis('off')
a = fig.add_subplot(1,4,3)
plt.imshow(dif_30, cmap=plt.get_cmap('gray'))
a.set_title('Abert (15)')
plt.axis('off')
plt.tight_layout()
plt.show() """
dif_open = folha - morphology.opening(folha, disk(radios))
""" fig = plt.figure(figsize=(100,100))
a = fig.add_subplot(1,2,1)
plt.imshow(folha, cmap=plt.get_cmap('gray'))
a.set_title('Original')
plt.axis('off')
a = fig.add_subplot(1,2,2)
plt.imshow(dif_open, cmap=plt.get_cmap('gray'))
a.set_title('Opening')
plt.axis('off')
plt.tight_layout()
plt.show() """