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: canopyCover.m
    path of file: ./repos/Digital-Forestry-Toolbox/scripts/canopy metrics
    
    the code of the file until where you have to start completion: function cover = canopyCover(chm, refmat, varargin)
% CANOPYCOVER - computes a canopy crown cover map
%
% COVER = CANOPYCOVER(CHM, REFMAT, ...) computes a canopy crown cover map using a 2D convolution or a variant of the Delaunay
% triangulation based method described in [1]. The cover map is computed from the georeferenced raster canopy height
% model CHM and tree locations STEMS (for the triangulation method).
%
% [1] L. Eysn, M. Hollaus, K. Schadauer, et N. Pfeifer, « Forest Delineation Based on Airborne LIDAR Data »,
% Remote Sensing, vol. 4, p. 762-783, march 2012.
%
% Syntax:  cover = canopyCover(chm, refmat, ...)
%
% Inputs:
%    chm - RxC numeric matrix, raster Canopy Height Model (CHM) with R rows
%    and C columns
%
%    refmat - 3x2 numeric matrix, spatial referencing matrix such that [map_x map_y] = [row col 1] * refmat
%
%    method (optional, default: 'convolution') - A string indicating which method to use for the
%    crown cover computation, either 'convolution' (default) or 'triangulation'
%
%    stems - Mx3 numeric matrix, column, row and height values for
%    each stem, [col, row, height]
%
%    label - RxC numeric matrix, individual tree crown label matrix with R rows
%    and C columns
%
%    minHeight (optional, default: 0.6) - numeric value, minimum canopy
%    height, all values below this threshold are set to zero.
%

    
function cover = canopyCover(chm, refmat, varargin)
% CANOPYCOVER - computes a canopy crown cover map
%
% COVER = CANOPYCOVER(CHM, REFMAT, ...) computes a canopy crown cover map using a 2D convolution or a variant of the Delaunay
% triangulation based method described in [1]. The cover map is computed from the georeferenced raster canopy height
% model CHM and tree locations STEMS (for the triangulation method).
%
% [1] L. Eysn, M. Hollaus, K. Schadauer, et N. Pfeifer, « Forest Delineation Based on Airborne LIDAR Data »,
% Remote Sensing, vol. 4, p. 762-783, march 2012.
%
% Syntax:  cover = canopyCover(chm, refmat, ...)
%
% Inputs:
%    chm - RxC numeric matrix, raster Canopy Height Model (CHM) with R rows
%    and C columns
%
%    refmat - 3x2 numeric matrix, spatial referencing matrix such that [map_x map_y] = [row col 1] * refmat
%
%    method (optional, default: 'convolution') - A string indicating which method to use for the
%    crown cover computation, either 'convolution' (default) or 'triangulation'
%
%    stems - Mx3 numeric matrix, column, row and height values for
%    each stem, [col, row, height]
%
%    label - RxC numeric matrix, individual tree crown label matrix with R rows
%    and C columns
%
%    minHeight (optional, default: 0.6) - numeric value, minimum canopy
%    height, all values below this threshold are set to zero.
%
%    filter (optional, default: ones(20,20)) - numeric matrix, convolution window (for convolution method only)
%
%    verbose (optional, default: true) - boolean value, verbosiy switch
%
%    fig (optional, default: true) - boolean value, switch to plot figures
%
% Outputs:
%    cover - RxC numeric matrix, canopy cover ratio
%
% Example:
%    pc = LASread('..\data\measurements\vector\als\so_2014_woodland_pasture.las');
%
%    [models, refmat] = elevationModels([pc.record.x, pc.record.y, pc.record.z], ...
%        pc.record.classification, ...
%        'classTerrain', 2, ...
%        'classSurface', 18, ...
%        'cellResolution', 1, ...
%        'closing', 10, ...
%        'smoothingFilter', fspecial('gaussian', [3, 3], 1), ...
%        'outputModels', {'terrain', 'surface', 'height'}, ...
%        'fig', true, ...
%        'verbose', true);
%
%    [crh, ~] = canopyPeaks(models.height.values, ...
%        refmat, ...
%        'method', 'allometricRadius', ...
%        'allometry', @(h) 0.5 + 0.25*log(max(h,1)), ...
%        'fig', true, ...
%        'verbose', true);
%
%    label = treeWatershed(models.height.values, ...
%        'markers', crh, ...
%        'minHeight', 1, ...
%        'fig', true, ...
%        'verbose', true);
%
%    cover_1 = canopyCover(models.height.values, ...
%        refmat, ...
%        'method', 'triangulation', ...
%        'stems', crh, ...
%        'label', label, ...
%        'verbose', true, ...
%        'fig', true);
%
%    cover_2 = canopyCover(models.height.values, ...
%        refmat, ...
%        'method', 'convolution', ...
%        'filter', ones(10,10), ...
%        'verbose', true, ...
%        'fig', true);
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
% Compatibility: tested on Matlab R2017b, GNU Octave 4.2.2 (configured for "x86_64-w64-mingw32")
%
% See also: elevationModels, canopyPeaks.m, treeWatershed.m
%
% This code is part of the Matlab Digital Forestry Toolbox
%
% Author: Matthew Parkan, EPFL - GIS Research Laboratory (LASIG)
% Website: http://mparkan.github.io/Digital-Forestry-Toolbox/
% Last revision: April 12, 2018
% Acknowledgments: This work was supported by the Swiss Forestry and Wood Research Fund (WHFF, OFEV), project 2013.18
% Licence: GNU General Public Licence (GPL), see https://www.gnu.org/licenses/gpl.html for details


%% check argument validity

arg = inputParser;

addRequired(arg, 'chm', @isnumeric);
addRequired(arg, 'refmat', @isnumeric);
addParameter(arg, 'method', 'convolution', @(x) ismember(x, {'convolution', 'triangulation'}));
addParameter(arg, 'stems', [], @(x) isnumeric(x) && size(x,1) >= 3);
addParameter(arg, 'label', [], @(x) isnumeric(x) && isequal(size(x), size(chm)));
addParameter(arg, 'minHeight', 1, @(x) isnumeric(x) && (numel(x) == 1));
addParameter(arg, 'filter', ones(20,20), @(x) isnumeric(x));
addParameter(arg, 'verbose', true, @(x) islogical(x) && (numel(x) == 1));
addParameter(arg, 'fig', true, @(x) islogical(x) && (numel(x) == 1));

parse(arg, chm, refmat, varargin{:});

%% load Octave packages

OCTAVE_FLAG = (exist('OCTAVE_VERSION', 'builtin') ~= 0); % determine if system is Matlab or GNU Octave

if OCTAVE_FLAG
    
    pkg load statistics
    pkg load image
    more off % disable pager
    
end