we want to make algorithms
(average) Md=1/(N^2-K) ∑||(x,y)-S(x,y)||
where N is the size of the block, S(x, y) is the location of the selected pixel nearest to the pixel at location (x, y) and K is the number of selected pixels. Lower the value of μd and σ2 d, the more is the spatial homogeneity of the sampling lattice.
For K=9
I write a matlab code for this algorithm. I didn't find what's wrong with code
for i=2:1:a-1
for j=2:1:b-1
S=blok(i-1:i+1;j-1:j+1);
sum=sum+abs(blok(i,j)-S(i,j));
end
end
Md =double(sum/((a*b)-9));
input is block 16x16 block=16x16 (piece of image)
i found S(x,y) making kernel[1 1 1; 1 1 1; 1 1 1] convolution with block
for i=1:1:14
for j=1:1:14
for m=-1:1
for n=-1:1
S(i+1,j+1)=S(i+1,j+1)+kernel(m+2,n+2).*blok(i-m+1,j-m+1);
end
end
% S=blok(i-1:i+1;j-1:j+1);
total=total+abs(blok(i+1,j+1)-S(i+1,j+1));
end
end
its seems work for now but ı am not sure.