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

Figure 4.1 - Hit-or-miss transform

Description

Rather than simply probe the inside or the outside of an image, it can be useful to probe both at the same time in order to study the relation between figure and background. The hit-or-miss transform requires two structuring elements, and , which are treated as a hit-or-miss template , with the assumption that . is used to probe the inside and to probe the outside, and the transform is defined by

A point is in the hit-or-miss output if and only if translated to the point fits inside and translated to the point fits outside . It is assumed and are disjoint, for otherwise it would be impossible for both fits to occur simultaneously.

Because it operates by fitting structuring elements into both the image and its complement, the hit-or-miss transform probes the relationship between the image and its complement relative to the structuring pair. Note that if is made of all zeros, the hit-or-miss degrades to the erosion by . The transform is illustrated in Figure 4.1. Rather than write the structuring pair, it is common practice to write a single template and to mark as foreground (1, or black) pixels in the template used for the hit structuring element , mark with background (0, or white) those used for the miss structuring element , and mark with an " " or simply not mark those pixels used for neither, these being the so-called "don't care" pixels.

Demo Script

 1 import ia870 as MT
 2 import ia636 as ia
 3 
 4 E = MT.iasecross()
 5 F = MT.iaframe(MT.iabinary(zeros((7,7))))
 6 i = MT.iase2hmt(E,F)
 7 
 8 S = MT.iabinary([
 9   [0,0,0,0,0,0,0,0,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,1,1,1,0,0,0,0,0,1,1,1,0,0],
12   [0,0,1,1,1,0,0,0,0,0,0,1,1,0,0],
13   [0,0,0,1,1,0,0,0,0,0,1,1,1,0,0],
14   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
15   [0,0,0,0,0,0,0,0,0,0,1,1,1,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,1,1,1,1,1,0],
18   [0,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
19   [0,0,1,1,0,0,0,0,0,1,1,1,1,1,0],
20   [0,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
21   [0,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
22   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]])
23 
24 T = MT.iasupgen(S,i)
25 
26 Eimg = MT.iapad(MT.iaseshow(E),MT.iasebox(2))
27 
28 fig_a = MT.iabshow(Eimg>=0,Eimg)
29 fig_b = MT.iabshow(F>=0,F)
30 fig_c = MT.iabshow(MT.iaunion(Eimg,F),Eimg)
31 
32 adshow(MT.ianeg(fig_a),'(a)')
33 adshow(MT.ianeg(fig_b),'(b)')
34 adshow(MT.ianeg(fig_c),'(c)')
35 
36 fig_d = MT.iabshow(S>=0,S)
37 fig_e = MT.iabshow(T>=0,T)
38 
39 adshow(MT.ianeg(fig_d),'(d)')
40 adshow(MT.ianeg(fig_e),'(e)')

(a)

(b)

(c)

(d)

(e)