Toolbox ia870 | List of Figures | Fig. 2.8 | Fig. 2.10

Figure 2.9 - Filtering pepper noise

Description

Opening can be used to filter pepper noise; closing can be used to filter salt noise. Figure 2.9 shows a text image, the image degraded by pepper noise, and the result of filtering the pepper degraded image by a 2 x 2 structuring element

Demo Script

 1 import numpy as np
 2 import ia870 as MT
 3 from handson.lib import iabggmodel
 4 
 5 f = adreadgray('MVBook/text1.png') > 0
 6 n = iabggmodel(shape(f),MT.iasecross(),1,0.003)
 7 n = MT.iadil(n,MT.iasecross())
 8 f_cor = MT.iaintersec(f,MT.ianeg(n))
 9 B = MT.iabinary([[1, 1],
10                  [1, 1]])
11 
12 g = MT.iaclose(f_cor,B)
13 
14 adshow(MT.iapad(f), '(a) uncorrupted image')
15 adshow(MT.iapad(f_cor), '(b) image corrupted with pepper noise')
16 adshow(MT.iapad(g), '(c) restoration by opening')

(a) uncorrupted image

(b) image corrupted with pepper noise

(c) restoration by opening