img=imread('westconcordorthophoto.png');
[m n]=size(img);
%snoise=0.5*randn(size(img));
%img=imadd(img,im2uint8(snoise));
%figure(2)
%imshow(img)
r=1; %邻域半径
imgn=zeros(m+2*r+1,n+2*r+1);
imgn(r+1:m+r,r+1:n+r)=img;
imgn(1:r,r+1:n+r)=img(1:r,1:n); %扩展上边界
imgn(1:m+r,n+r+1:n+2*r+1)=imgn(1:m+r,n:n+r); %扩展右边界
imgn(m+r+1:m+2*r+1,r+1:n+2*r+1)=imgn(m:m+r,r+1:n+2*r+1); %扩展下边界
imgn(1:m+2*r+1,1:r)=imgn(1:m+2*r+1,r+1:2*r); %扩展左边界
Hist=zeros(256,256);
for i=1+r:r+m
for j=1+r:r+n
pix1=uint8(imgn(i,j));
pix2=uint8(mean2(imgn(i-r:i+r,j-r:j+r)));
Hist(pix1+1,pix2+1)=Hist(pix1+1,pix2+1)+1;
end
end
mesh(double(Hist))