%EUSIPCO 2012
%Imperial College London 
%Andriy Gelman, Jon Onativia and Pier Luigi Dragotti

function [output, total_bits] = lossless_encode_segmentation(input)

%check whether input is a cell - if not then make the input of type cell
if ~iscell(input)
    new_input{1} = input; input = new_input; clear new_input;
end

output = cell(0);
for l = 1:length(input)
    if length(unique(input{l})) > 1
        buffer = encode_layer(input{l}, 1);
        output(1,length(output)+1:length(output)+length(buffer)) = buffer;
    end
end
total_bits = 0;
for l=1:length(output)
    total_bits = total_bits + length(output{l});
    
end