function dataOut = augmentGroundTruthObjectsToLidarData(dataIn,sampledGTData,indices,classNames,numObjects)
    ptCloud = dataIn{1,1};
    bboxesGt = dataIn{1,2};
    bboxesClasses = dataIn{1,3};          
           
    % Convert point cloud to Mx4 format.
    ptCloud = removeInvalidPoints(ptCloud);
    ptCloud = cat(2,ptCloud.Location,ptCloud.Intensity);
                 
    matFile = sampledGTData.UnderlyingDatastores{1,1}.Files;
    blData = sampledGTData.UnderlyingDatastores{1,2}.LabelData;
                        
    for i = 1:numel(classNames)          
        % To remove the pitch and roll from the box coordinates.   
        if ~isempty(bboxesGt)
            bboxesGt = bboxesGt(:,[1,2,3,4,5,6,9]);
        end
             
        % Calculate the number of boxes to add.
        if(~isempty(dataIn{1,3}))
            numPCToAdd = numObjects(i) - sum(dataIn{1,3} == classNames(i));
            numPCToAdd = max(numPCToAdd,0); 
        else
            numPCToAdd = numObjects(i);
        end
            
        idx = find(strcmp(indices,classNames{i}));
        objIdx = randperm(numel(idx),numPCToAdd);
        finalIndices = idx(objIdx);
        pcToAdd = cell(numPCToAdd,1);
        bboxesToAdd = zeros(numPCToAdd,7);
        for q=1:numPCToAdd                   
            sampledPoints = load(matFile{finalIndices(q),1});
            boxData = blData{finalIndices(q),1};
            bboxesToAdd(q,:) = boxData([1,2,3,4,5,6,9]);
            pcToAdd{q,1} = sampledPoints.(char(fieldnames(sampledPoints)));
        end        
           
        % Find overlap within the selected boxes.
        if ~isempty(bboxesToAdd)
            bboxesBEV = bboxesToAdd(:,[1,2,4,5,7]);
            boxscores  = rand(size(bboxesBEV,1),1);
            [~,~,idx] = selectStrongestBbox(bboxesBEV,boxscores,'OverlapThreshold',0);
            bboxesToAdd = bboxesToAdd(idx,:);
            pcToAdd = pcToAdd(idx);
        end

        % Condition wherein both ground truth boxes and boxes to add
        % are present.
        if ~isempty(bboxesGt) && ~isempty(bboxesToAdd)
            overlapRatio = bboxOverlapRatio(bboxesToAdd(:,[1,2,4,5,7]),bboxesGt(:,[1,2,4,5,7]));
            maxOverlap = max(overlapRatio,[],2);
            bboxesToAddFinal = bboxesToAdd(maxOverlap == 0,:);
            pcToAddFinal = pcToAdd(maxOverlap == 0);
            finalGtBoxes = [bboxesGt;bboxesToAddFinal];
            pcToAddClasses = cell(size(bboxesToAddFinal,1),1);
            pcToAddClasses(:) = {classNames{i}};
            pcToAddClasses = categorical(pcToAddClasses);
            finalClasses = cat(1,bboxesClasses,pcToAddClasses);

        % Condition wherein there are no ground truth boxes.
        elseif isempty(bboxesGt)
            bboxesToAddFinal = bboxesToAdd;
            pcToAddFinal = pcToAdd;
            finalGtBoxes = bboxesToAdd;
            pcToAddClasses = cell(size(finalGtBoxes,1),1);
            pcToAddClasses(:) = {classNames{i}};
            pcToAddClasses = categorical(pcToAddClasses);
            finalClasses = pcToAddClasses;

        % Condition wherein there are no bboxes to add to the
        % existing ground truths.
        elseif isempty(bboxesToAdd)
            finalGtBoxes = bboxesGt;
            bboxesToAddFinal = [];
            finalClasses = bboxesClasses;
        end

        % Extract the points inside the boxes and append to point
        % cloud.
        if ~isempty(bboxesToAddFinal)
            for ii = 1:size(bboxesToAddFinal,1)
                pointsToAdd = pcToAddFinal{ii};
                if isempty(pointsToAdd)
                    continue;
                end
                ptCloud = [ptCloud;pointsToAdd];
            end
        end            
       finalBoxes = zeros([size(finalGtBoxes,1),9]);
       finalBoxes(:,1:6) = finalGtBoxes(:,1:6);
       finalBoxes(:,9) = finalGtBoxes(:,7);
       bboxesGt = finalBoxes;
       bboxesClasses = finalClasses;    
   end     
       pcout = pointCloud(ptCloud(:,1:3));
       pcout.Intensity = ptCloud(:,4);
       dataOut{1,1} = pcout;
       dataOut{1,2} = finalBoxes;
       dataOut{1,3} = finalClasses;            
end            