Img = zeros(10, 10) + 10;

for n=3:7
   for m=3:7
      Img(n,m) = 30;
   end;
end;

for n=1:10
   for m=1:10
      Img(n,m) = Img(n,m) + normrnd(0,2);
   end;
end;

figure(1)
colormap(gray)
image(Img)

X = [];
for m=1:10
   X = [X; Img(m, :)'];
end;

X = [X, zeros(100, 1)];

Y = pdist(X);
Z = linkage(Y); 
T = cluster(Z, 2);

Img2 = [];
n = 1;
for m=1:10
   Img2 = [Img2; T(n: m*10)'];
   n = n + 10;
end;

figure(2)
colormap(gray)
image(Img2*10)
