With the Image Processing Toolbox, you can use the nfilter
function.
Test=triu(ones(100));
f = @(x) numel(x(x==1))/numel(x);
I2 = nlfilter(Test,[10 10],f);
Result:
And then do what's necessary to deal with border artifacts. I suspect there are more efficient ways of doing this (using column-wise processing), but it's a start.