The docstring isn't completely clear to me. However, I have the impression that this is not what the code does: the code does first 2*n dilations, followed by n erosions.