Have a look at "morphological image processing"

http://www.dspguide.com/ch25/4.htm