I have a large binary matrix. I want to reduce the size of this matrix by using knn-approximation. What my idea is to cluster the matrix in groups of 4 neighbors and replace the group with a 1, if the number of 1s in the group is greater than or equal to the number of zeros.
To be concrete, let the matrix be
1 0 0 1 0
0 1 1 0 0
1 1 0 0 0
0 1 1 1 0
0 0 1 1 0
1 0 0 1 0
First I want to create neighborhood group as
1 0 |0 1| 0|
0 1 |1 0| 0|
------------
1 1 |0 0| 0|
0 1 |1 1| 0|
------------
0 0 |1 1| 0|
------------
and then the final matrix I want to generate is
1 1 0
1 1 0
0 1 0
by replacing the group with the majority score. How can I efficiently do this is MATLAB?