% generate new skeleton from old skeleton points

function [new_skeleton, new_points_skeleton] = GenerateNewSkeleton(points_skeleton,optreg)


img_width = optreg.img_width;
img_height = optreg.img_height;
new_frame = optreg.new_frame;

new_skeleton = zeros(img_height, img_width, new_frame(3));
number_points_skeleton_original = size(points_skeleton,1);

new_number_points_skeleton = nnz(points_skeleton)/3;
new_points_skeleton = zeros(new_number_points_skeleton,3);

% What follows is a waste of memory and CPU time.  Might need
% to fix if gets too slow.

ticker = 1;
for j = 1:number_points_skeleton_original
    if ~isequal(squeeze(points_skeleton(j,:)),[0 0 0])
        x_coord = points_skeleton(j,1);
        y_coord = points_skeleton(j,2);
        z_coord = points_skeleton(j,3);
        new_skeleton(y_coord,x_coord,z_coord) = 1;
        new_points_skeleton(ticker,:) = points_skeleton(j,:);
        ticker = ticker+1;
    end
end

end