This is the only change compared to morphologicalDilate, I would propose to merge both functions and give them a min/max parameter.