% FUNKCIJA KOJA VRŠI ODŠUMLJAVANJE SLIKE OVISNO O BROJU
%RAZINA DEKOMPOZICIJE

function [imgR]=odsumi(imgGN,N)

warning off MATLAB:conv2:uint8Obsolete

[R,S]=size(imgGN);

% prva razina
A1=zeros(ceil(R/2),ceil(S/2));
H1=zeros(ceil(R/2),ceil(S/2));
V1=zeros(ceil(R/2),ceil(S/2));
D1=zeros(ceil(R/2),ceil(S/2));

% druga razina
A2=zeros(ceil(R/4),ceil(S/4));
H2=zeros(ceil(R/4),ceil(S/4));
V2=zeros(ceil(R/4),ceil(S/4));
D2=zeros(ceil(R/4),ceil(S/4));

% treca razina
A3=zeros(ceil(R/8),ceil(S/8));
H3=zeros(ceil(R/8),ceil(S/8));
V3=zeros(ceil(R/8),ceil(S/8));
D3=zeros(ceil(R/8),ceil(S/8));

% cetvrta razina
A4=zeros(ceil(R/16),ceil(S/16));
H4=zeros(ceil(R/16),ceil(S/16));
V4=zeros(ceil(R/16),ceil(S/16));
D4=zeros(ceil(R/16),ceil(S/16));

% peta razina
A5=zeros(ceil(R/32),ceil(S/32));
H5=zeros(ceil(R/32),ceil(S/32));
V5=zeros(ceil(R/32),ceil(S/32));
D5=zeros(ceil(R/32),ceil(S/32));


% prva razina dekompozicije
[A1,H1,V1,D1]=moj2dfwt(imgGN);


if N>1
    [A2,H2,V2,D2]=moj2dfwt(A1);

end;

if N>2
    [A3,H3,V3,D3]=moj2dfwt(A2);

end;

if N>3
    [A4,H4,V4,D4]=moj2dfwt(A3);


end;

if N>4
    [A5,H5,V5,D5]=moj2dfwt(A4);


end;



% Proces odšumljavanja uz rekurzivnu rekonstrukciju
% Kreèe se od "najviše" razine

if N>4
    k=5;
    [H5,V5,D5]=odsumljavanje_2(A5,H5,V5,D5,k);
    [A4]=moj2difwt(A5,H5,V5,D5);
    
end

if N>3
    k=4;
    [H4,V4,D4]=odsumljavanje_2(A4,H4,V4,D4,k);
    [A3]=moj2difwt(A4,H4,V4,D4);
    
end


if N>2
    k=3;
    [H3,V3,D3]=odsumljavanje_2(A3,H3,V3,D3,k);
    [A2]=moj2difwt(A3,H3,V3,D3);
    
end

if N>1
    k=2;
    [H2,V2,D2]=odsumljavanje_2(A2,H2,V2,D2,k);
    [A1]=moj2difwt(A2,H2,V2,D2);
    
end

%zadnja razina razlaganja

k=1;
[H1,V1,D1]=odsumljavanje_2(A1,H1,V1,D1,k);
imgR=moj2difwt(A1,H1,V1,D1);

    
