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: xASL_im_M0ErodeSmoothExtrapolate.m
    path of file: ./repos/ExploreASL/Functions/ImageProcessing
    
    the code of the file until where you have to start completion: function [ImOut, VisualQC] = xASL_im_M0ErodeSmoothExtrapolate(ImIn, DirOutput, NameOutput, pvGM, pvWM, brainCentralityMap, LowThreshold)
%xASL_im_M0ErodeSmoothExtrapolate M0 image processing
%

    
function [ImOut, VisualQC] = xASL_im_M0ErodeSmoothExtrapolate(ImIn, DirOutput, NameOutput, pvGM, pvWM, brainCentralityMap, LowThreshold)
%xASL_im_M0ErodeSmoothExtrapolate M0 image processing
%
% FORMAT: [ImOut, VisualQC] = xASL_im_M0ErodeSmoothExtrapolate(ImIn, DirOutput, NameOutput, pvGM, pvWM, brainCentralityMap[, LowThreshold])
%
% INPUT:
%   ImIn - unprocessed M0 image, as 3D image or path (REQUIRED)
%   DirOutput - sring path to output folder, used to be x.D.M0regASLdir (REQUIRED)
%   NameOutput - string for filename in ['M0_im_proc_' NameOutput '.jpg'] (REQUIRED)
%   pvGM  - unprocessed pvGM image (3D image or path, same space as M0 image (REQUIRED)
%   pvWM  - unprocessed pvWM image (3D image or path, same space as M0 image (REQUIRED)
%   brainCentralityMap - brain mask probability map multiplied by centrality map, as 3D image or path (REQUIRED)
%   LowThreshold - numerical value between 0 and 1 for percentile sorted images values that will define the inclusion mask (mask>LowThreshold)
%                   (OPTIONAL, DEFAULT=0.7)
%
% OUTPUT:
%   ImOut    - processed M0 image
%   VisualQC - visualization of the M0 processing steps for quality control
% OUTPUT FILES: Visual QC image of M0 processing
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION:  This function erodes, smooths & extrapolates M0 in MNI standard space (tested at 1.5x1.5x1.5mm as used in ExploreASL).
%               It assumes that the M0 image is in standard space & that the GM & WM probability maps
%               are aligned. Here, we mask the M0, to remove high CSF signal and low extracranial signal,
%               enabling us to smooth the image without inserting wrong signal. See also
%               the ExploreASL manuscript for a more extensive explanation. 
%
%               A visual QC figure is created, showing the M0 image processing steps for a single transversal slice (slice 53 in `1.5 mm` MNI standard space)
%               `OutputFile = fullfile(DirOutput,['M0_im_proc_' NameOutput '.jpg']);`
%               The original M0 image (a) is masked with a (pGM+pWM)>50% mask (b)
%               eroded with a two-voxel sphere to limit the influence of the ventricular and extracranial signal (c)
%               and thresholded to exclude significantly high (i.e. median + 3*mean absolute deviation (MAD)) border region values (d)
%               This masked M0 image is smoothed with a 16x16x16 mm full- width-half-maximum Gaussian filter (Mutsaerts et al., 2018) (e)
%               after which the signal at the border is smoothly extrapolated until the full image is filled (f).
%               Whereas the masking avoids mixing with cerebrospinal fluid or extracranial signal, the extrapolation avoids M0 division artifacts
%
%               This function performs the following steps:
%
%               1.  Mask 1: structural mask
%               2.  Mask 2: intensity-based mask to remove extracranial signal
%               2.a Multiplication with brain mask centrality map
%               2.b Mask the "dummy image" from 2.a based on intensities
%               2.c Enforce to include the eroded brain in the mask
%               3.  Mask 3: Erode the combined masks
%               4.  Mask 4: Determine any odd borders
%               5.  Smoothing
%               6.  Extrapolating only
%               7.  Scale back to the GM M0
%               8.  Print visual QC figure
%
% EXAMPLE: as used in ExploreASL (xASL_wrp_ProcessM0): [ImOut] = xASL_im_M0ErodeSmoothExtrapolate(x.P.Pop_Path_M0, x.D.M0regASLdir, x.P.SubjectID, x.P.Pop_Path_rc1T1, x.P.Pop_Path_rc2T1, path_BrainCentralityMap)
% __________________________________
% Copyright (C) 2015-2021 ExploreASL


%% ------------------------------------------------------------------------------------------
%% 0. Admin
if nargin < 1 || isempty(ImIn)
    error('Please specify M0 image to be processed');
elseif nargin < 2 || isempty(DirOutput)
	error('Please specify output folder');
elseif nargin < 3 || isempty(NameOutput)
	error('Please specify the output name');
elseif nargin < 4 || isempty(pvGM)
	error('Please specify the pvGM');
elseif nargin < 5 || isempty(pvWM)
	error('Please specify the pvWM');
elseif nargin < 6 || isempty(brainCentralityMap)
	error('Please specify the brainCentralityMap');
elseif nargin < 7 || isempty(LowThreshold)
    LowThreshold = 0.7;
elseif ~isnumeric(LowThreshold)
    error('Invalid LowThreshold input parameter, should be numerical');
elseif LowThreshold<0 || LowThreshold>1
    error('Invalid LowThreshold value, should be between 0 and 1');
end