Toolbox ia870 | List of Figures | Fig. 4.2 | Fig. 4.4

Figure 4.3 - Object recognition using hit-or-miss

Description

The Figure 4.3 shows a practical application of template matching using the hitor- miss transform. The goal is to detect the ground symbol in an electronic circuit drawing. The designed template is shown on part (a) of the figure, and in part (b) the detected symbols are highlighted on the input image. Note that the template has few hit and miss points to fit five quite different ground symbols. The result of the hit-or-miss transform was conditionally dilated by a rectangle of the same size as the hit template relative to the input image to reveal only the detected symbols.

Demo Script

 1 import ia870 as MT
 2 import ia636 as ia
 3 
 4 
 5 f = adreadgray('circuit_bw.tif')>0
 6 
 7 hit = MT.iabinary([
 8  [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
 9  [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
10  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
11  [0,0,0,1,1,1,1,1,1,1,1,1,0,0,0],
12  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
13  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
14  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
15  [0,0,0,0,1,1,1,1,1,1,1,0,0,0,0],
16  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
17  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
18  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
19  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
20  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
21  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]])
22 
23 miss  =  MT.iabinary([
24  [0,1,1,1,0,0,0,0,0,0,0,1,1,1,0],
25  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
26  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
27  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
28  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
29  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
30  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
31  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
32  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
33  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
34  [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
35  [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
36  [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
37  [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]])
38 
39 D = MT.iaimg2se(MT.iaunion(hit,1))
40 I = MT.iase2hmt(MT.iaimg2se(hit),MT.iaimg2se(miss))
41 y = MT.iacdil(MT.iasupgen(f,I),f,D)
42 
43 fig_a = MT.iabshow(MT.iaunion(hit,miss),hit)
44 fig_b = MT.iagshow(MT.ianeg(f),y)
45 adshow(MT.iapad(MT.ianeg(fig_a)), '(a) hit-or-miss template')
46 adshow(fig_b,'(b) ground symbol detected')

(a) hit-or-miss template

(b) ground symbol detected