Refactor mathematical morphology methods.