Find the Grid of Region Average
Slide a 3 by 3 window over the image. A window counts only when every neighbouring pair inside it is within the threshold. Each valid window contributes its floored mean to its pixels, and each pixel takes the floored average of those contributions.