function x = SA(y,mu,sigma,x,beta,M,invT)

[row_max,col_max] = size(y);

for row = 1:row_max
for col = 1:col_max
 s = [row,col];
 for k = 1:2
  E(k) = energy(k,s,y,mu,sigma,x,beta);
 end

 deltaE = E(2)-E(1);
 prob = 1/(1+exp(-deltaE));

 r = random('Uniform',0,1,1,1);
 if r<prob 
   x(row,col) = 1;
 else
   x(row,col) = 2;
 end
end
end

