% perturb the 2D image function, the First Argument in input % returns pertubed image = pimage function pimage = perturb (p, up, g, alpha, T) % form the perturbed image [m,n] = size (p); % generate random number matrix uniformly distributed % over the range [-0.5,0.5] rp = random ('unif',-0.5,0.5,m,n); %interV = 50 * sqrt(T); %rp = random ('unif',-interV,interV,m,n); pimage = p + alpha .* rp; % impose non-negativity constraint pimage (find (pimage < 0.0) ) = 0; % Calculate the change in cost function delta_Q = cost_simannealing (pimage,up,g) - cost_simannealing (p,up,g); % Decide to accept the pertubation or not rd = random ('unif',0,1); if ( (delta_Q > 0.0) & (exp(-delta_Q /T) < rd) ) % do not accept the perturbation pimage = p; end