# Figure 3.8 - 8-connected boundaries

## Description

Figure 3.8 does the same for the 4-neighbors mask [see Fig. 3.7]. Notice how the square mask has yielded 4-connected boundaries, whereas the 4-neighbors mask has yielded only 8-connected boundaries. While there may sometimes be an advantage in having a 4-connected boundary, for small image components it can look “cluttered,” especially the internal boundary. Thicker boundaries can be obtained by using larger structuring elements.

## Demo Script

``` 1 import numpy as np
2 import ia870 as MT
3
4 S=mmbinary([
5    [0,0,0,0,0,0,0,0,0],
6    [0,0,0,1,1,1,0,0,0],
7    [0,0,0,1,1,1,0,0,0],
8    [0,1,1,1,1,1,1,1,0],
9    [0,1,1,1,1,1,1,1,0],
10    [0,1,1,1,1,1,1,1,0],
11    [0,0,0,1,1,1,1,1,0],
12    [0,0,0,1,1,1,1,1,0],
13    [0,0,0,0,0,1,0,0,0],
14    [0,0,0,0,0,0,0,0,0]])
15
16 DS = MT.iathreshad(S,0)
17
18 B0 = MT.iasecross(0)
19 B4 = MT.iasecross()
20 B8 = MT.iasebox()
21
22 a = MT.iabshow(DS,S)
23 b = MT.iabshow(DS, MT.iadil(S,B4))
24 c = MT.iabshow(DS,MT.iaero(S,B4))
25 d = MT.iabshow(DS,MT.iagradm(S,B4,B0))
26 e = MT.iabshow(DS,MT.iagradm(S,B0,B4))
27 f = MT.iabshow(DS,MT.iagradm(S,B8,B4))
28
29 adshow(MT.ianeg(a), '(a) input image')
30 adshow(MT.ianeg(b), '(b) dilation')
31 adshow(MT.ianeg(c), '(c) erosion')
32 adshow(MT.ianeg(d), '(d) 8-connected external boundary')
33 adshow(MT.ianeg(e), '(e) 8-connected internal boundary')