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


function output_label = compute_spatial_decomposition_label(label, number_of_decompositions)

if number_of_decompositions > 0 
    %Compute Label
    %label(abs(label)>0)= 1;
    output_label = zeros(size(label));
    buffer = label;
    for i = 1:number_of_decompositions

        LL = buffer(1:2:end,1:2:end);
        LH = buffer(1:2:end,2:2:end);
        HL = buffer(2:2:end,1:2:end);
        HH = buffer(2:2:end,2:2:end);
    
        buffer_label = [LL, LH; HL, HH];
        [r1,c1] = size(buffer_label);
        output_label(1:r1,1:c1) = buffer_label;
        buffer = LL;
    end
else
    output_label = label;
end