File size: 7,415 Bytes
17e2002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
1
00:00:01,660 --> 00:00:03,980
So let's explore dilution and erosion.

2
00:00:04,030 --> 00:00:09,670
These are two very important open CVF operations and are quite useful in image processing.

3
00:00:09,760 --> 00:00:12,880
So the best way to explain this is by looking at examples here.

4
00:00:12,940 --> 00:00:14,590
So this is a letter s here.

5
00:00:14,620 --> 00:00:19,660
It's a white letter on a black box all which is what the zeros and ones correspond to.

6
00:00:19,660 --> 00:00:24,600
You can consider the ones to be 255 if you want just a Munteanu open see Visa on it.

7
00:00:24,820 --> 00:00:30,440
So let's look at what erosion does erosion removes pixels at the boundaries of an object of an image.

8
00:00:30,700 --> 00:00:35,920
What it means is that the boundaries of the object the object being a letter s here.

9
00:00:36,170 --> 00:00:40,640
Imagine everything is gone here and the bargees itself.

10
00:00:40,720 --> 00:00:42,590
That's exactly what erosion does.

11
00:00:42,610 --> 00:00:49,570
So we get it out that s dilation whoever does the opposite dilution that adds pixel to the boundaries

12
00:00:49,570 --> 00:00:50,990
of an object here.

13
00:00:51,010 --> 00:00:55,210
So this is why it becomes much Tica in our dilated segment here.

14
00:00:56,200 --> 00:01:01,200
So what about opening Andalus in here opening and closing are really useful functions that combined

15
00:01:01,270 --> 00:01:03,060
dilution and intuition together.

16
00:01:03,340 --> 00:01:10,850
So opening is erosion followed by dilation and closing is the opposite dilution followed by erosion.

17
00:01:11,230 --> 00:01:16,080
As you can imagine an erosion followed by dilution would be very useful in getting rid of noise.

18
00:01:16,300 --> 00:01:19,020
So imagine if it was some little white specks in this image.

19
00:01:19,180 --> 00:01:25,720
If we Rojos images and does become Tendo to one visit or disappear altogether then we'd do a dilution.

20
00:01:25,750 --> 00:01:28,010
We actually preserve the initial image here.

21
00:01:28,020 --> 00:01:30,220
We want to maintain.

22
00:01:30,450 --> 00:01:36,150
So no dilution and erosion while simple actually causes a lot of confusion with first timers who try

23
00:01:36,150 --> 00:01:41,930
to use it at all because there's a false misconception about what it does now.

24
00:01:41,940 --> 00:01:42,540
Yes it does.

25
00:01:42,540 --> 00:01:47,640
Dilution does in fact add pixels to the boundaries of an object and erosion does remove pixels at the

26
00:01:47,640 --> 00:01:48,830
boundaries of an object.

27
00:01:49,050 --> 00:01:56,310
However imagine we have a black X on a white bacterial open even to produce this white as being the

28
00:01:56,310 --> 00:01:57,370
object itself.

29
00:01:57,600 --> 00:02:03,180
So when we run an erosion here it's actually going to erode into this you see erosion is actually going

30
00:02:03,180 --> 00:02:08,450
to have the thickening effect of dilution and the dilution is going to have the opposite effect.

31
00:02:08,460 --> 00:02:13,440
It's going to have the thinning effect that we expect and erosion to have because what's happening here

32
00:02:13,440 --> 00:02:16,900
is that the boundaries of the image are basically in the points here.

33
00:02:17,190 --> 00:02:23,580
So when we direly it we're actually making white bigger on the edges of all P and whatever else happens

34
00:02:23,660 --> 00:02:25,600
if you would here.

35
00:02:25,740 --> 00:02:27,300
So please don't get them confused.

36
00:02:27,300 --> 00:02:30,610
It happens quite often it happened to me actually.

37
00:02:30,630 --> 00:02:32,310
So don't feel bad if it happens to you.

38
00:02:33,980 --> 00:02:39,680
So let's not look at implementing dilution erosion opening and closing you know a code.

39
00:02:39,720 --> 00:02:44,380
So the first thing to note is that we actually need to define a kernel and we define it by using non-place

40
00:02:44,470 --> 00:02:46,690
ones function data type here.

41
00:02:47,070 --> 00:02:49,280
And we have a five by five.

42
00:02:49,350 --> 00:02:50,980
You know exampled.

43
00:02:52,130 --> 00:02:56,080
So to erode function and daily function both follow the same pattern here.

44
00:02:56,340 --> 00:03:01,950
We take that input image couldn't say as we defined here and iterations which is how many times you

45
00:03:01,950 --> 00:03:02,810
run it.

46
00:03:03,030 --> 00:03:05,670
In most cases you would never need to run this more than once.

47
00:03:05,670 --> 00:03:12,840
However if you do run it to a tree or whatever amount of times you actually increase effect it's running

48
00:03:12,840 --> 00:03:15,450
the erosion twice and same image.

49
00:03:15,510 --> 00:03:16,470
So let's run this.

50
00:03:16,480 --> 00:03:19,080
I mean take a look and see what happens.

51
00:03:19,080 --> 00:03:24,760
So this is the open C-v text which I wrote out in Windows beant this is it.

52
00:03:24,770 --> 00:03:25,580
It really did.

53
00:03:25,740 --> 00:03:28,810
As you can see it has the effect of what we anticipated.

54
00:03:28,830 --> 00:03:32,560
It actually erodes the boundaries here.

55
00:03:34,700 --> 00:03:36,150
Making it much tighter.

56
00:03:36,590 --> 00:03:38,000
And let's see dilution now.

57
00:03:40,880 --> 00:03:42,160
Exactly as we anticipated.

58
00:03:42,170 --> 00:03:45,770
So as you can see dilution adds pixels the edges here.

59
00:03:45,770 --> 00:03:50,910
So it actually everything appears much thicker as if it was written with a marker and not a pen.

60
00:03:51,110 --> 00:03:59,910
And that's look at opening is the effects of erosion then dilution.

61
00:03:59,930 --> 00:04:06,180
So as you can see here because just when he wrote it actually disappeared these boundaries here when

62
00:04:06,180 --> 00:04:06,770
we dilated.

63
00:04:06,770 --> 00:04:12,180
No it actually misses these things totally because there's nothing to dilate the underside here.

64
00:04:12,500 --> 00:04:16,470
So that's why opening so that's whole opening has this effect on image here.

65
00:04:16,470 --> 00:04:20,780
So let's look at closing now no closing actually looks quite nice.

66
00:04:20,780 --> 00:04:25,870
And the reason for that is because closing is dilution first then eroding.

67
00:04:25,880 --> 00:04:31,540
So what we did here actually should get us back something to a very original image and actually it does.

68
00:04:31,550 --> 00:04:38,140
If you look at it is actually pretty much to see him just barely noticeable.

69
00:04:38,180 --> 00:04:42,980
So these operations that we've just seen are actually called morphology operations and they're actually

70
00:04:42,980 --> 00:04:48,210
a few more you can take a look at this link to view the eye is open see these official documentation

71
00:04:48,250 --> 00:04:48,950
site.

72
00:04:49,130 --> 00:04:53,050
However they aren't as useful as erudition and erosion in my opinion.

73
00:04:53,090 --> 00:04:57,490
But however you may have a special uses for it so feel free to check them out.