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: cat_main_LAS.m
    path of file: ./repos/ExploreASL/External/SPMmodified/toolbox/cat12
    
    the code of the file until where you have to start completion: function [Yml,Ymg,Ycls,Ycls2,T3th] = cat_main_LAS(Ysrc,Ycls,Ym,Yb0,Yy,T3th,res,vx_vol,extopts,Tth) 
% This is an exclusive subfunction of cat_main.
% ______________________________________________________________________
%
% Local Adaptive Segmentation (LAS):
%
% This version of the local adaptive intensity correction includes a  
% bias correction that is based on a maximum filter for the WM and a mean
% filter of GM to stabilize the correction in region with less WM.
% The extension is mostly based on the assumption that the tissue next to 
% the CSF (and high divergence sulci) has to be WM (maximum, high 
% divergence) or GM. For each tissue a refined logical map is generated 
% and used to estimate the local intensity threshold.
% It is important to avoid high intensity blood vessels in the process, 
% because they will push down local WM and GM intensity - due to the CSF
% near possition of blood vessels that mostly push down GM. 
% Based on these values an intensity transformation is used. Compared to 
% the global correction this has to be done for each voxel. To save time
% only a rough linear transformation is used.
%
% Finally, a second NLM-filter is used and a refinement of WM structures
% by a divergence map 
% ______________________________________________________________________
%
%   [Yml,Ycls,Ycls2,T3th] = ...
%     cat_main_LAS(Ysrc,Ycls,Ym,Yb0,Yy,T3th,res,vx_vol,PA,template)
%
%   Yml    .. local intensity correct image
%   Ycls   .. corrected SPM tissue class map
%   Ycls2  .. ?
%   T3th   .. tissue thresholds of CSF, GM, and WM in Ysrc
%
%   Ysrc   .. (bias corrected) T1 image
%   Ym     .. intensity corrected T1 image (BG=0,CSF=1/3,GM=2/3,WM=1)
%   Ycls   .. SPM tissue class map
%   Yb0    .. brain mask
%   Yy     .. deformation map
%   res    .. SPM segmentation structure
%   vx_vol .. voxel dimensions
%   PA     .. CAT atlas map
%   template .. ?
% ______________________________________________________________________
% 
% internal maps:
%
%   Yg   .. gradient map   - edges between tissues
%   Ydiv .. divergence map - sulci, gyris pattern, and blood vessels
%   Yp0  .. label map      - tissue classes (BG=0,CSF=1,GM=2,WM=3) 
%
%   Ysw  .. save WM tissue map
%   Ybv  .. blood vessel map
%   Ycp  .. CSF / background area for distances estimation
%   Ycd  .. CSF / background distance
%   Ycm  .. CSF
%   Ygm  .. GM

    
function [Yml,Ymg,Ycls,Ycls2,T3th] = cat_main_LAS(Ysrc,Ycls,Ym,Yb0,Yy,T3th,res,vx_vol,extopts,Tth) 
% This is an exclusive subfunction of cat_main.
% ______________________________________________________________________
%
% Local Adaptive Segmentation (LAS):
%
% This version of the local adaptive intensity correction includes a  
% bias correction that is based on a maximum filter for the WM and a mean
% filter of GM to stabilize the correction in region with less WM.
% The extension is mostly based on the assumption that the tissue next to 
% the CSF (and high divergence sulci) has to be WM (maximum, high 
% divergence) or GM. For each tissue a refined logical map is generated 
% and used to estimate the local intensity threshold.
% It is important to avoid high intensity blood vessels in the process, 
% because they will push down local WM and GM intensity - due to the CSF
% near possition of blood vessels that mostly push down GM. 
% Based on these values an intensity transformation is used. Compared to 
% the global correction this has to be done for each voxel. To save time
% only a rough linear transformation is used.
%
% Finally, a second NLM-filter is used and a refinement of WM structures
% by a divergence map 
% ______________________________________________________________________
%
%   [Yml,Ycls,Ycls2,T3th] = ...
%     cat_main_LAS(Ysrc,Ycls,Ym,Yb0,Yy,T3th,res,vx_vol,PA,template)
%
%   Yml    .. local intensity correct image
%   Ycls   .. corrected SPM tissue class map
%   Ycls2  .. ?
%   T3th   .. tissue thresholds of CSF, GM, and WM in Ysrc
%
%   Ysrc   .. (bias corrected) T1 image
%   Ym     .. intensity corrected T1 image (BG=0,CSF=1/3,GM=2/3,WM=1)
%   Ycls   .. SPM tissue class map
%   Yb0    .. brain mask
%   Yy     .. deformation map
%   res    .. SPM segmentation structure
%   vx_vol .. voxel dimensions
%   PA     .. CAT atlas map
%   template .. ?
% ______________________________________________________________________
% 
% internal maps:
%
%   Yg   .. gradient map   - edges between tissues
%   Ydiv .. divergence map - sulci, gyris pattern, and blood vessels
%   Yp0  .. label map      - tissue classes (BG=0,CSF=1,GM=2,WM=3) 
%
%   Ysw  .. save WM tissue map
%   Ybv  .. blood vessel map
%   Ycp  .. CSF / background area for distances estimation
%   Ycd  .. CSF / background distance
%   Ycm  .. CSF
%   Ygm  .. GM
%   Ywm  .. WM 
%   Yvt  .. WM next to the ventricle map 
% ______________________________________________________________________
%
%   Robert Dahnke (robert.dahnke@uni-jena.de)
%   Structural Brain Mapping Group (http://dbm.neuro.uni-jena.de/)
%   Department of Neurology
%   University Jena
% ______________________________________________________________________
% $Id: cat_main_LAS.m 1561 2020-02-04 15:49:34Z gaser $


  def.uhrlim = 0.7; 
  extopts = cat_io_checkinopt(extopts,def); 
  extopts.uhrlim = 0.2;  % the reduction to 1 mm was not realy good for the Ycls map
  
  
  % set this variable to 1 for simpler debuging without reduceBrain
  % function (that normally save half of processing time)
  verb    = extopts.verb-1;
  vxv     = 1/ mean(vx_vol);
  dsize   = size(Ysrc);
  NS      = @(Ys,s) Ys==s | Ys==s+1;                                    % function to ignore brain hemisphere coding
  LASstr  = max(eps,min(1,extopts.LASstr));  % LAS strenght (for GM/WM threshold)3 - manual correction based on R1109 (2017/02)
  LAB     = extopts.LAB;                         % atlas labels
  LABl1   = 1;                                                          % use atlas map
  cleanupstr  = min(1,max(0,extopts.gcutstr));   % required to avoid critical regions
  cleanupdist = min(3,max(1,1 + 2*cleanupstr));
    
  % set debug = 1 and do not clear temporary variables if there is a breakpoint in this file 
  dbs   = dbstatus; debug = 0; 
  for dbsi=1:numel(dbs), if strcmp(dbs(dbsi).name,'cat_main_LAS'); debug = 1; break; end