Toolbox ia870 | List of Figures | Fig. 4.1 | Fig. 4.3

Figure 4.2 - Recognition of noisy object

Description

Use of the hit-or-miss transform for object recognition is straightforward; nonetheless, like most recognition schemes, application to real-world images is highly problematic and requires various adaptations of the basic algorithm. We illustrate the approach with reference to a particular example.

In Fig. 4.2 there is an image composed of six objects: a rectangle, a square, a square with a small extrusion, and also the same three objects with noisy edges. If our task is to mark the location of the clean square-with-extrusion, then we can proceed by forming a structuring element that is an exact copy of the desired shape. Erosion of the image by the square-with-extrusion will yield a single marked point, the point of the origin where the structuring element fits exactly. In the present circumstance erosion accomplishes matching.

Figure 4.2 Recognition of noisy object. The exact hit-or-miss template can, where: (a) Input image , (b) Template , (c) , (d) Template and (e)

Demo Script

 1 import ia870 as MT
 2 import ia636 as ia
 3 import numpy as np
 4 from handson.lib import iabggmodel
 5 
 6 Z = MT.iabinary(zeros((100,100)))
 7 
 8 A = np.array(Z)
 9 A[19:80,34:65] = 1
10 
11 B = np.array(Z)
12 B[24:75,24:75] = 1
13 
14 C = np.array(B)
15 C[14:30,39:60] = 1
16 
17 F = MT.iaconcat('W',A,B,C)
18 
19 hit = np.array(B)
20 miss = MT.iagradm(B,MT.iasebox(2),MT.iasebox(0))
21 
22 b1 = MT.iaimg2se(hit)
23 b2 = MT.iaimg2se(miss)
24 
25 I = MT.iase2hmt(b1,b2)
26 G = MT.iasupgen(F,I)
27 
28 p = MT.iagray(MT.iaunion(hit,1),'uint8',128)
29 
30 T = MT.iaintersec(MT.iaunion(MT.iagray(hit),p),MT.ianeg(MT.iagray(miss)))
31 
32 Na = iabggmodel(shape(F),MT.iasecross(),2,0.05)
33 Ns = MT.ianeg(iabggmodel(shape(F),MT.iasecross(),2,0.05))
34 Fn = MT.iaareaclose(MT.iadil(MT.iaareaopen(MT.iaintersec(MT.iaunion(F,Na),Ns),100)),20)
35 
36 hit_n = MT.iaero(hit,MT.iasebox(4))
37 b1n = MT.iaimg2se(hit_n)
38 miss_n = MT.iagradm(MT.iadil(hit,MT.iasebox(4)), MT.iasebox(2),MT.iasebox(0))
39 b2n = MT.iaimg2se(miss_n)
40 
41 In = MT.iase2hmt(b1n,b2n)
42 Gn = MT.iasupgen(Fn,In)
43 Tn = MT.iaintersec(MT.iaunion(MT.iagray(hit_n),p),MT.ianeg(MT.iagray(miss_n)))
44 
45 H = MT.iaconcat('W',F, Fn)
46 
47 G1 = MT.iasupgen(H,I)
48 G2 = MT.iasupgen(H,In)
49 
50 fig_a = H
51 fig_b = T
52 fig_c = MT.iadil(G1,MT.iasebox())
53 fig_d = Tn
54 fig_e = MT.iadil(G2,MT.iasebox())
55 
56 adshow(MT.iapad(MT.ianeg(fig_a)), '(a)')
57 adshow(MT.ianeg(fig_b), '(b)')
58 adshow(MT.iapad(MT.ianeg(fig_c)), '(c)')
59 adshow(MT.ianeg(fig_d), '(d)')
60 adshow(MT.iapad(MT.ianeg(fig_e)), '(e)')

(a)

(b)

(c)

(d)

(e)