Separating averaging window core algorithm so that it can be reused for grid detection.