function [controlPoints, contour] = annealer(imageFile, tempVect, sampleNum, spacing) % Main function of the Simulated Annealing program. % Finds a contour traversing the image from side to side by a simulated % annealing algorithm. % % syntax: % [controlPoints, contour] = annealer(imageFile, tempVect, sampleNum, spacing) % % input/output variables: % imageFile name of the file containing the image % tempVect vector of (descending) temperatures % sampleNum number of samples at each step % spacing horizontal spacing between control points % % controlPoints the vector of control points % contour the vector of contour points % Read the image and compute its potential energy I = rgb2gray(imread(imageFile)); U = potentialEnergy(I); % Initialize auxiliary variables [nRows, nCols] = size(I); nControlPoints = floor( nCols / spacing ) + 3; % Initialize the array of controlpoints and the contour controlPoints = nRows / 2 * ones(nControlPoints, 1); contour = formBspline(controlPoints, spacing); % Main loop for Temp = TempVect, % Choose a random order to follow in visiting the control points order = randperm(nControlPoints); % Adjust each control point once following the order for j = 1:nControlPoints, [controlPoints, contour] = ... gibbsSampler(U,controlPoints,contour,spacing,Temp,order(j),sampleNum); end end