Toolbox ia870 | List of Figures | Fig. 2.5 | Fig. 2.7

Figure 2.6 - Effects of digital opening and closing

Description

To see the pixel effect of opening and closing, consider the image and structuring element of Fig. 1.14, the opening and closing being shown in Fig. 2.6. As a filter, opening has cleaned the boundary by eliminating small extrusions; however, it has done this in a much finer manner than erosion, the net effect being that the opened image is a much better replica of the original than the eroded image.

Analogous remarks apply to the closing, the difference being the filling of small intrusions. Note that whereas the position of the origin relative to the structuring element has a role in both erosion and dilation, it plays no role in opening and closing.

Demo Script

 1 import numpy as np
 2 import ia870 as MT
 3 
 4 S = adreadgray('MVBook/g.png') > 0
 5 E = MT.iabinary([[0, 0, 0],
 6                 [0, 1, 1],
 7                 [0, 1, 1]])
 8 T = MT.iaopen(S,E)
 9 U = MT.iaclose(S,E)
10 frame = MT.iaunion(S,1)
11 
12 adshow(MT.ianeg(MT.iabshow(frame,S)), '(a) Input image')
13 adshow(MT.ianeg(MT.iaseshow(E,'EXPAND')), '(b) structuring element')
14 adshow(MT.ianeg(MT.iabshow(frame,T)), '(c) opening')
15 adshow(MT.ianeg(MT.iabshow(frame,U)), '(d) closing')

(a) Input image

(b) structuring element

(c) opening

(d) closing