

function [block_output, block_output_label, state_counter] = spatial_shape_adaptive_DWT(input, label, number_of_decompositions, maximum_block_size)

if ~isempty(input)
[r,c] = size(input);

label(label>0)=1;
if number_of_decompositions > 0
    [output] = SA_DWT_full_decomposition(input, label, number_of_decompositions);
    output_label = compute_spatial_decomposition_label(label, number_of_decompositions);
    %[output, output_label] =
    %spatial_shape_adaptive_transform_matlab(input, label, number_of_decompositions);
else
    output_label = label;
    output = input;
end

output = round(output);
[block_output, state_counter] = partition_subband(output, number_of_decompositions, maximum_block_size);
block_output_label = partition_subband(output_label, number_of_decompositions, maximum_block_size);

else
    state_counter = 0;
    block_output = [];
    block_output_label = [];
end
end


function output = divide_et_impera(input, iterations)
output = input;
for i = 1:iterations
    
    for ii = 1:length(output)
        buffer((ii-1)*2+1:ii*2) = [ceil(output(ii)/2), floor(output(ii)/2)];
    end
    output = buffer;

end
end



