This figure illustrates the use of opening and closing for restoration of salt-and-pepper noise.
.
from morph import *
from handson import *
from Numeric import shape
f=mmreadgray('text1.tif')
n_salt=mmbggmodel(shape(f),mmsecross(),1,0.1)
n_pepper=mmbggmodel(shape(f),mmsecross(),1,0.1)
fbin=mmintersec(mmunion(f,n_salt),mmneg(n_pepper))
B=mmbinary([[1, 1], [1, 1]])
g=mmasf(fbin,'oc',B,1)
mmshow(fbin)
mmshow(g)