I have a large matrix of 1's and 0's, and am looking for a way to "fill" up areas that are locally dense with 1's. 
I first did this task for an array, and counted the number of 1's within a certain radius of the element in questions. If the radius was 5, for example, and my threshold was 4, then a point that had 4 elements marked "1" within 5 elements to the left or right would be changed to a 1.

Basically I would like to generalized this to a two - dimensional array and have a resulting matrix that has "smooth" and "connected" regions of 1's and no "patchy" spots.

As an example, the matrix

1 0 0 1 0 0 0 

0 0 1 0 1 0 0

0 1 0 1 0 0 0 

0 0 1 1 1 0 0 

would ideally be changed to

1 0 0 1 1 0 0 

0 0 1 1 1 0 0

0 1 1 1 1 0 0 

0 0 1 1 1 0 0 

or something similar