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: doCompileOccurenceTextonsNN.m
    path of file: ./repos/Image-Harmonization-Dataset-iHarmony4/Lalonde and Efros/colorStatistics/mycode
    
    the code of the file until where you have to start completion: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function doCompileOccurencesTextonsSplit
%   Compiles the textons results obtained from the training data
% 
% Input parameters:
%
% Output parameters:
%
%    
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function doCompileOccurenceTextonsNNglobal histoImg histoBg histoObj indObj indImg nbImg nbObjects;
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2006-2007 Jean-Francois Lalonde
% Carnegie Mellon University
% Do not distribute
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
function dbFnCompileOccurenteTextonsNN(annotation, dbPath, outputBasePath, varargin)
global histoImg histoBg histoObj indObj indImg nbImg nbObjects;

if isfield(annotation, 'colorStatisticsTextons5x5ObjBgUnsorted')
    if (isfield(annotation.colorStatisticsTextons5x5ObjBgUnsorted, 'file'))
        % load the histogram
        load(fullfile(dbPath, annotation.image.folder, annotation.colorStatisticsTextons5x5ObjBgUnsorted.file));
        
        nbImg = nbImg + 1;

        % stack it onto the existing histogram
        nbObjCur = size(textonHistObj, 1);
        
        histoImg(nbImg,:) = single(full(textonHistImg'));
        
        histoBg(nbObjects+1:nbObjects+nbObjCur, :) = single(full(textonHistBg));
        histoObj(nbObjects+1:nbObjects+nbObjCur, :) = single(full(textonHistObj));
        
        indObj(nbObjects+1:nbObjects+nbObjCur, :) = (1:size(textonHistObj, 1))';
        indImg(nbObjects+1:nbObjects+nbObjCur, :) = repmat(nbImg, size(textonHistObj, 1), 1);
        
        nbObjects = nbObjects + nbObjCur;
    end