You may use imdilate
to get you the maximum of a 9x9 neighbhorhood -
%%// Dilate to get the max of a 9x9 neighborhood (including the element itself)
A1 = imdilate(A, true(3));
%%// Since you are looking to keep the boundary elements
m1 = ones(size(A));
m1(2:end-1,2:end-1)=0;
A1 = m1.*A+~m1.*A1
If you are looking to get the maximum of a 8x8 neighbhorhood, i.e. exclude the element itself, use a modified kernel for use into imdilate
-
%%// Dilate to get the max of a 8x8 neighborhood (excluding the element itself)
h = true(3);
h(2,2)=false;
A1 = imdilate(A,h);
%%// Since you are looking to keep the boundary elements
m1 = ones(size(A));
m1(2:end-1,2:end-1)=0;
A1 = m1.*A+~m1.*A1