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: pm_unwrap.m
    path of file: ./repos/bspm/thirdparty/spm12/toolbox/FieldMap
    
    the code of the file until where you have to start completion: function varargout = pm_unwrap(varargin)
% Unwrapping of phasemap
% When measuring phase one cannot easily distinguish between e.g. a phase
% of 182 degrees, and one of -178 degrees. One tries to distinguish these
% cases by using neighbourhood information. So in the example above, if we
% find that a neighbouring voxel has a phase of 150 degres it seems much
% more likely that the "true" phase is 182 degrees than -178 degrees. It's
% trickier than it sounds.
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(ci,pxs,method)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(ci,pxs)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(P,method)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(P)
% 
% Input:
% ci          : Complex image volume corresponding
%               to  abs(te2).*exp(i*angle(te2))./exp(i*angle(te1));
%               where te1 and te2 corresponds to the complex
%               images obtained with the short and the long
%               echo-time respectively, and i denotes sqrt(-1).
% pxs         : 3x1 (or 2x1) array with pixel sizes.
% 
% or
%
% P           : File structure (from) spm_vol, containing complex
%               image volume as per above.
%
% method      : Determines which method should be used
%               for phase-unwrapping. The options are
%               'Huttonish', 'Mark2D', 'Mark3D' and 'hybrid'.
% 'Huttonish' : Loosely (hence -ish) based on method described
%               in Hutton et al. Gets an estimate of the 
%               uncertainty of the phase angle at each point
%               and unwraps in a "watershed" fashion from
%               a high certainty seed towards more uncertain
%               areas.
% 'Mark2D'    : Method suggested for high-res data in 
%               Jenkinssons MRM paper.
% 'Mark3D'    : Method suggested for low-res data in
%               Jenkinssons MRM paper.
%
% Output:
% upm         : Phasemap (corresponding to angle(ci))
%               after unwrapping of phase jumps.
% angvar      : Map of the variance of the phase-angle
%               estimates. This is used internally to
%               guide the unwrapping procedure, and
%               can also be used if one whishes to
%               do a weighted fitting of some smooth
%               basis set to the unwrapped phasemap.
% mask        : Binary mask indicating what voxels
%               have been unwrapped.
% opm         : angle(ci)
%               
% Light reading:
% 
% Examples of water-shed/flood-fill based unwrapping 
% algorithms:
%
% Hutton C, Bork A, Josephs O, Deichmann R, Ashburner J,
% Turner R. 2002. Image distortion correction in fMRI: A
% quantitative evaluation. NeuroImage 16:217-240.

% Cusack R & Papadakis N. 2002. New robust 3-D phase unwrapping
% algorithms: Application to magnetic field mapping and
% undistorting echoplanar images. NeuroImage 16:754-764.
%
% Region-merging based unwrapping algorithm.
%
% Jenkinson M. 2003. Fast, automated, N-dimensional phase-
% unwrapping algorithm. MRM 49:193-197.
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Jesper Andersson 
% $Id: pm_unwrap.m 5659 2013-09-27 12:38:24Z guillaume $

%
% The following are a set of parameters that
% guide the phase unwrapping. Some are general
% (i.e. apply to all methods) and some are specific.
%

%
% These general parameters appear fine for a wide
% variety of phase-map data.

    
function varargout = pm_unwrap(varargin)
% Unwrapping of phasemap
% When measuring phase one cannot easily distinguish between e.g. a phase
% of 182 degrees, and one of -178 degrees. One tries to distinguish these
% cases by using neighbourhood information. So in the example above, if we
% find that a neighbouring voxel has a phase of 150 degres it seems much
% more likely that the "true" phase is 182 degrees than -178 degrees. It's
% trickier than it sounds.
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(ci,pxs,method)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(ci,pxs)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(P,method)
% or
% FORMAT: [upm,(angvar),(mask),(opm)] = pm_unwrap(P)
% 
% Input:
% ci          : Complex image volume corresponding
%               to  abs(te2).*exp(i*angle(te2))./exp(i*angle(te1));
%               where te1 and te2 corresponds to the complex
%               images obtained with the short and the long
%               echo-time respectively, and i denotes sqrt(-1).
% pxs         : 3x1 (or 2x1) array with pixel sizes.
% 
% or
%
% P           : File structure (from) spm_vol, containing complex
%               image volume as per above.
%
% method      : Determines which method should be used
%               for phase-unwrapping. The options are
%               'Huttonish', 'Mark2D', 'Mark3D' and 'hybrid'.
% 'Huttonish' : Loosely (hence -ish) based on method described
%               in Hutton et al. Gets an estimate of the 
%               uncertainty of the phase angle at each point
%               and unwraps in a "watershed" fashion from
%               a high certainty seed towards more uncertain
%               areas.
% 'Mark2D'    : Method suggested for high-res data in 
%               Jenkinssons MRM paper.
% 'Mark3D'    : Method suggested for low-res data in
%               Jenkinssons MRM paper.
%
% Output:
% upm         : Phasemap (corresponding to angle(ci))
%               after unwrapping of phase jumps.
% angvar      : Map of the variance of the phase-angle
%               estimates. This is used internally to
%               guide the unwrapping procedure, and
%               can also be used if one whishes to
%               do a weighted fitting of some smooth
%               basis set to the unwrapped phasemap.
% mask        : Binary mask indicating what voxels
%               have been unwrapped.
% opm         : angle(ci)
%               
% Light reading:
% 
% Examples of water-shed/flood-fill based unwrapping 
% algorithms:
%
% Hutton C, Bork A, Josephs O, Deichmann R, Ashburner J,
% Turner R. 2002. Image distortion correction in fMRI: A
% quantitative evaluation. NeuroImage 16:217-240.

% Cusack R & Papadakis N. 2002. New robust 3-D phase unwrapping
% algorithms: Application to magnetic field mapping and
% undistorting echoplanar images. NeuroImage 16:754-764.
%
% Region-merging based unwrapping algorithm.
%
% Jenkinson M. 2003. Fast, automated, N-dimensional phase-
% unwrapping algorithm. MRM 49:193-197.
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Jesper Andersson 
% $Id: pm_unwrap.m 5659 2013-09-27 12:38:24Z guillaume $

%
% The following are a set of parameters that
% guide the phase unwrapping. Some are general
% (i.e. apply to all methods) and some are specific.
%

%
% These general parameters appear fine for a wide
% variety of phase-map data.
%
% General
%
mthres = (pi^2)/6; % Angular uncertainty threshold for mask.
ndil = 1;          % No. of erode->dilate when creating mask.
rr = 0;            % Should we remove linear ramps prior to unwrapping?

%
% These parameters guide the progression of the
% unwrapping waterfront. We have found it very 
% difficult to find a set of parameters that work
% for "all" data sets. Sometimes it is better to
% "pour" quickly in the beginning (large fthres) 
% and very slowly towards the end