%Shape adaptive DWT implementation used from QCC Pack by James E. Fowler
%http://qccpack.sourceforge.net/index.shtml

function [output] = SA_DWT_full_decomposition(input, label, number_of_decompositions)

if number_of_decompositions > 0
    [r,c,k] = size(input);
    output = zeros(r,c,k);

    %buffer_input = input;
    buffer_label = label;
    %{
    for i = 1:number_of_decompositions    
        %Find the size of input
        [length_rows, length_columns] = size(buffer_input); 
        %Apply one decomposition on the input signal
        [output(1:length_rows,1:length_columns), label(1:length_rows,1:length_columns),rows_label ]=  three_D_lifting_shape_adaptive_9_7_1_decomposition(buffer_input, buffer_label);
        %Extract Low Pass
        buffer_input = output(1:ceil(length_rows/2), 1: ceil(length_columns/2));
        buffer_label = label(1:ceil(length_rows/2), 1:ceil(length_columns/2));
    end    
    %}




    icpwrite('label.icp', label);
    icpwrite('input.icp', input);
    nl = num2str(number_of_decompositions);
    dos_string = ['imgdwt -nl ',nl, ' -m label.icp input.icp dwt_output.icp'];
    %dos_string = ['imgdwt -nl ',nl, ' input.icp dwt_output.icp'];

    dos(dos_string);

    %output = read_dwt('dwt_output.icp');
    dos_string = ['sbptoicp dwt_output.icp buffer.icp'];
    dos(dos_string);
    output = icpread('buffer.icp');

    %label = [];
    %rows_label = [];

    %Read data 

else 
    output = input;

end