Fast Morphological Erosion / Dilation with Variable Window Size
The trick when using masks is that if the window is shifted one to the left, only one row is added and one removed. Therefore one can e.g. calculate the mean of a 5x5 window quicker, as if all 25 values needed to be added and divided again.

In erosion or dilation this fact could be used to, if one would store the max of each row. Then only the maxes of one new row would be needed and a comparison between all rows. However I guess nobody does that, since the overhead is quite big and big windows would need additional space for each row's max...

Your problem however couldn't even use this, since the window size is changing. I assume the changes are random. Therefore there will be no quicker way than moving from pixel to pixel and apply the different window sizes.

But why would someone use different windows for different pixels?