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: local_AC_MS.m
    path of file: ./repos/Active-Contour-Model-Matlab/LocalizedActiveContour
    
    the code of the file until where you have to start completion: function seg = local_AC_MS(Img,mask_init,rad,alpha,num_it,epsilon)
% This function aims to implement Shawn Lankton's local active contour. And
% the energy model is the MS model as defined in eq.(15)-(19).
% The local variables are calculated by filtering operation instead of
% iterating inspired by Chunming Li's IEEE TIP 2008 paper
%
% One small change is that I used a square window instead of disk for
% localization
%
% Input: 
% 1. Img: image needs to be segmented
% 2. mask_init: intialization represented by binary image
% 3. rad: the side length of the square window
% 4. alpha: the coeficicent to balance the image fidality term and the
% curvature regularization term
% 5. num_it: maximum number of iterations
% 6. epsilon: epsilon used for delta and heaviside function
% Created by Jincheng Pang, Tufts University @11/09/2012

phi0 = mask2phi(mask_init);
phi = phi0;

B0 = ones(2*rad+1,2*rad+1);  
% B0 = fspecial('disk',rad);

KI=conv2(Img,B0,'same');  
KONE=conv2(ones(size(Img)),B0,'same'); 


for ii = 1:num_it
mask = Heaviside2(phi,epsilon);

I=Img.*mask;
temp1=conv2(mask,B0,'same');                             
temp2=conv2(I,B0,'same');                             
c1=temp2./(temp1);    % local mean value inside                                    
c2=(KI-temp2)./(KONE-temp1); % local mean value outside 

A1 = temp1;
A2 = conv2(1-mask,B0,'same');
%%%%% 

    
function seg = local_AC_MS(Img,mask_init,rad,alpha,num_it,epsilon)
% This function aims to implement Shawn Lankton's local active contour. And
% the energy model is the MS model as defined in eq.(15)-(19).
% The local variables are calculated by filtering operation instead of
% iterating inspired by Chunming Li's IEEE TIP 2008 paper
%
% One small change is that I used a square window instead of disk for
% localization
%
% Input: 
% 1. Img: image needs to be segmented
% 2. mask_init: intialization represented by binary image
% 3. rad: the side length of the square window
% 4. alpha: the coeficicent to balance the image fidality term and the
% curvature regularization term
% 5. num_it: maximum number of iterations
% 6. epsilon: epsilon used for delta and heaviside function
% Created by Jincheng Pang, Tufts University @11/09/2012

phi0 = mask2phi(mask_init);
phi = phi0;

B0 = ones(2*rad+1,2*rad+1);  
% B0 = fspecial('disk',rad);

KI=conv2(Img,B0,'same');  
KONE=conv2(ones(size(Img)),B0,'same'); 


for ii = 1:num_it
mask = Heaviside2(phi,epsilon);

I=Img.*mask;
temp1=conv2(mask,B0,'same');                             
temp2=conv2(I,B0,'same');                             
c1=temp2./(temp1);    % local mean value inside                                    
c2=(KI-temp2)./(KONE-temp1); % local mean value outside 

A1 = temp1;
A2 = conv2(1-mask,B0,'same');
%%%%% 
D = (A1.*A2+eps);
term1 = (A2-A1)./D;
term2 = (A2.*c1.^2-A1.*c2.^2)./D;
term3 = (A2.*c1-A1.*c2)./D;
dataForce = conv2(term1.*Dirac2(phi,epsilon),B0,'same').*Img.*Img + conv2(term2.*Dirac2(phi,epsilon),B0,'same')-2.*Img.*conv2(term3.*Dirac2(phi,epsilon),B0,'same');  %%% During the implementation, Img should be separated out of the filtering operation!!!
% dataForce = conv2(term1.*Dirac2(phi,epsilon).*Img.^2,B0,'same') + conv2(term2.*Dirac2(phi,epsilon),B0,'same')-2.*conv2(term3.*Dirac2(phi,epsilon).*Img,B0,'same');
dataForce = dataForce/max(abs(dataForce(:)));
% % curvature = get_curvature1(phi);
curvature = curvature_central(phi); 
dphi = Dirac2(phi,epsilon).*(-dataForce + alpha*curvature);

dt = .48/(max(abs(dphi(:)))+eps);

%-- evolve the curve
phi = phi + dt.*dphi;

%-- Keep SDF smooth
 phi = sussman(phi, .5);

    if(mod(ii,10) == 0) 
      showCurveAndPhi(Img,phi,ii);  
    end