function [seg_id, seg_sz, seg_gt] = get_seg_info(seg_map, gt_map)

% Unique segment identifiers from the label map.
seg_id = unique(seg_map);
seg_id(seg_id < 1) = [];

% Determine the size of each segment.
seg_sz = zeros(size(seg_id));
for i = 1:length(seg_id)
    seg_sz(i) = sum(sum(seg_map == seg_id(i)));
end

seg_gt = []
if ((nargin > 1) && ~isempty(gt_map))
    % Determine the ground truth label for each segment.
    gt_size = [size(gt_map) 1];
    gt_map  = reshape(gt_map,  [prod(gt_size([1 2])) gt_size(3)]);
    seg_map = reshape(seg_map, [prod(gt_size([1 2])) 1]);

    seg_gt = zeros(length(seg_id), gt_size(3));
    for i = length(seg_id)
        % Get the labels belonging to this segment
        pix_labels = gt_map(seg_map == seg_id(i), :);

        valid_labels = all(pix_labels >= 0, 2);
        pix_labels = pix_labels(valid_labels, :);

        [unq_labels, ~, unq_inds] = unique(pix_labels, 'rows');
        mode_ind = mode(unq_inds);
        seg_gt(i, :) = unq_labels(mode_ind, :);
    end
end
