Eroding and dilating images using morphological filters