function [shape] = reconstruct_subsampled_contours(verts, subsamp_fact, a, b, width, height)
% -------------------------------------------------------------------------
% MSc Project - MSc in Communications and Signal Processing
% Department of Electrical and Electronic Engineering
% Imperial College London, 2011
%
% Supervisor  : Dr Pier Luigi Dragotti
% Contributor : Andriy Gelman
% Author      : Jon Onativia Bravo
%
% File        : reconstruct_subsampled_contours.m
% -------------------------------------------------------------------------
% 
%
% [shape] = reconstruct_subsampled_contours(verts, subsamp_fact, a, b, width, height)
%
% INPUT:
%  - 
%
% OUTPUT:
%  - 
%

% Convert verts to original image's coordinates
orig_verts   = zeros(size(verts));
segment_inds = find(verts(1,:) == 0);
seg_lengths  = verts(2,segment_inds);
num_of_segs  = length(segment_inds);

for ith_seg = 1 : num_of_segs
    seg_start = segment_inds(ith_seg);
    orig_verts(2,seg_start) = seg_lengths(ith_seg);

    seg_end   = seg_start + seg_lengths(ith_seg);
    seg_start = seg_start + 1;

    orig_verts(1,seg_start:seg_end) ...
        = (verts(1,seg_start:seg_end) - 1) * subsamp_fact + a;
    orig_verts(2,seg_start:seg_end) ...
        = (verts(2,seg_start:seg_end) - 1) * subsamp_fact + b;

end

% Reconstruct shape
shape = contour2shape(orig_verts, width, height);


end
