You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: imChamferDistance.m
    path of file: ./repos/matImage/matImage/imGeodesics
    
    the code of the file until where you have to start completion: function dist = imChamferDistance(img, varargin)

    
function dist = imChamferDistance(img, varargin)
%IMCHAMFERDISTANCE Chamfer distance transform using scanning algorithm
%
%   WARNING: function imChamferDistance is obsolete, please use
%   imDistanceMap instead.
%
%   RES = imChamferDistance(IMG, MARKERS);
%   where IMG and MARKERS are binary images, computes for each foreground
%   pixel the minimum distance to the marker, using a path that is
%   contained in the foreground. If the markers can not be reached from a
%   foreground pixel, the corresponding result is Inf.
%   The function propagates distances to orthogonal and diagonal pixels,
%   using weights equal to 1 for orthogonal pixels, and sqrt(2) for
%   diagonal markers. The result RES is given in a double array the same
%   size as IMG.
%
%   The function uses scanning algorithm. Each iteration consists in a
%   sequence of a forward and a backward scan. Iteration stops when
%   stability is reached.
%
%   RES = imChamferDistance(IMG);
%   Assumes the marker image is given by the complement of the image IMG.
%   In this case, the behaviour is similar to the functin bwdist.
%
%   RES = imChamferDistance(..., WEIGHTS);
%   Specifies different weights for computing distance between 2 pixels.
%   WEIGHTS is a 2 elements array, with WEIGHTS(1) corresponding to the
%   distance between two orthonal pixels, and WEIGHTS(2) corresponding to
%   the distance between two diagonal pixels.
%   Possible choices
%   WEIGHTS = [1 sqrt(2)]   -> quasi-euclidean distance
%   WEIGHTS = [1 Inf]       -> "Manhattan" or "cityblock" distance
%   WEIGHTS = [1 1]         -> "Chessboard" distance
%   WEIGHTS = [3 4]         -> Borgerfors' weights (default)
%   WEIGHTS = [5 7]         -> close approximation of sqrt(2)
%   Results are normalized by the value of the first weight.
%
%   Note: when specifying weights, the result has the same class/data type
%   than the array of weights. It is possible to balance between speed and
%   memory usage:
%   - if weights are double (the default), the memory usage is high, but
%       the result can be given in pixel units 
%   - if weights are integer (for Borgefors weights, for example), the
%       memory usage is reduced, but representation limit of datatype can
%       be easily reached. One needs to divide by the first weight to get
%       result comparabale with natural distances.
%       For uint8, using [3 4] weigths, the maximal computable distance is
%       around 255/3 = 85 pixels. Using 'int16'  seems to be a good
%       tradeoff, the maximal distance with [3 4] weights is around 11000
%       pixels.
%
%   RES = imChamferDistance(..., 'verbose', true);
%   Displays info on iterations.
%
%   Example
%   % computes distance function inside a complex particle
%     img = imread('circles.png');
%     marker = false(size(img));
%     marker(80, 80) = 1;
%     % compute using quasi-enclidean weights
%     dist = imChamferDistance(img, marker);
%     figure; imshow(dist, []);
%     colormap(jet); title('Quasi-euclidean distance');
%     % compute using integer weights, giving integer results
%     dist34 = imChamferDistance(img, marker, int16([3 4]));
%     figure; imshow(double(dist34)/3, [0 max(dist34(img))/3]);
%     colormap(jet); title('Borgefors 3-4 weights');
%
%
%   % uses the examples from bwdist with different distances
%     img = ones(255, 255);
%     img(126, 126) = 0;
%     res1 = imChamferDistance(img);
%     res2 = imChamferDistance(img, [1 inf]);
%     res3 = imChamferDistance(img, [1 1]);
%     res4 = imChamferDistance(img, [1 1.5]);
%     figure;
%     subplot(221); subimage(mat2gray(res1));
%     hold on; imcontour(res1); title('quasi-euclidean');
%     subplot(222); subimage(mat2gray(res2));
%     hold on; imcontour(res2); title('city-block');
%     subplot(223); subimage(mat2gray(res3));
%     hold on; imcontour(res3); title('chessboard');
%     subplot(224); subimage(mat2gray(res4));
%     hold on; imcontour(res4); title('approx euclidean');
%
%   
%   See also
%   imGeodesics, imDistanceMap

% ------
% Author: David Legland
% e-mail: david.legland@nantes.inra.fr
% Created: 2009-05-19,    using Matlab 7.7.0.471 (R2008b)
% Copyright 2009 INRA - Cepia Software Platform.

%   HISTORY
%   2010.08.25 fix memory allocation for large images, add vebosity option

% Implementation notes
% This function uses a special processing for first and last lines, 
% and for first and last pixels of each regular line. Then it is not
% necessary to test if neighbor coordiantes are within image bounds,
% resulting in a somewhat faster algorithm. 
% However, this induces an increase in code complexity.

warning('MatImage:imGeodesics:deprecated', ...
    'function imChamferDistance is obsolete, use imDistanceMap instead');

%% Process input arguments

% default weights for orthogonal or diagonal neighbors
weights = [3 4];    
% normalize map by default
normalizeMap = true;
% empty markers by default
markers = [];
% no verbosity
verbose = false;

% extract markers if they are given as parameter
if ~isempty(varargin)
    var = varargin{1};
    if ndims(var) == ndims(img) && sum(size(var) ~= size(img)) == 0
        % use binarised markers
        markers = var > 0;
        varargin(1) = [];
    end