# Figure 4.4 - Sequential thinning with a single hit-or-miss template

## Description

The figure 4.4 illustrates the procedure for successive iteration with the single template operating on the image . Owing to the geometry of the structuring elements, the hit-or-miss transform marks lower-left corners of the image, and at each stage in the iteration these are removed by the thinning.

Because only a single template is employed in Fig. 4.4, the thinning is directional. By cycling through a set of eight “compass” templates, thinning is accomplished in a more symmetric manner.

## Demo Script

``` 1 import ia870 as MT
2 import ia636 as ia
3
4 S = MT.iabinary([
5     [0,0,0,0,0,0,0,0],
6     [0,1,1,1,1,1,0,0],
7     [0,1,1,1,1,1,1,0],
8     [0,1,1,1,1,1,1,0],
9     [0,0,0,0,1,1,1,0],
10     [0,0,0,0,1,1,1,0],
11     [0,0,0,0,1,1,1,0],
12     [0,0,0,0,0,0,0,0]])
13
14 B1 = MT.iabinary([[0,1,1],
15              [0,1,1],
16              [0,0,0]])
17
18 B2 = MT.iabinary([[1,1,1],
19              [0,1,1],
20              [0,0,1]])
21
22 I = MT.iase2interval(MT.iaimg2se(B1),MT.iaimg2se(B2))
23
24 S1 = MT.iasubm(S,MT.iasupgen(S,I))
25 S2 = MT.iasubm(S1,MT.iasupgen(S1,I))
26 S3 = MT.iasubm(S2,MT.iasupgen(S2,I))
27 S4 = MT.iasubm(S3,MT.iasupgen(S3,I))
28 S5 = MT.iasubm(S4,MT.iasupgen(S4,I))
29
30 fig_a = MT.iabshow(MT.iaunion(B1,MT.ianeg(B2)),B1)
31 fig_b = MT.iabshow(S>=0,S)
32 fig_c = MT.iabshow(S>=0,S1)
33 fig_d = MT.iabshow(S>=0,S2)
34 fig_e = MT.iabshow(S>=0,S3)
35 fig_f = MT.iabshow(S>=0,S4)
36 fig_g = MT.iabshow(S>=0,S5)
37
38 adshow(MT.ianeg(fig_a), '(a) Template T')
39 adshow(MT.ianeg(fig_b), ' (b) S')
40 adshow(MT.ianeg(fig_c), ' (c) S1')
41 adshow(MT.ianeg(fig_d), ' (d) S2')
42 adshow(MT.ianeg(fig_e), ' (e) S3')
43 adshow(MT.ianeg(fig_f), ' (f) S4')
44 adshow(MT.ianeg(fig_g), ' (g) S5')
```