function x = ICM(y,mu,sigma,x,beta,M)

[row_max,col_max] = size(y);

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

 Emin = min(E);
 kmin = find(E==Emin);
 x(row,col) = kmin(1);
end
end

