function wpak2im(c)
% WPAK2IM - Zobrazeni koeficientu 2D transformace Wavelet Packet
%   WPAK2IM usporada a zobrazi koeficienty 2D transformace Wavelet Packet
%   dane vstupem C. 
% 
%   Obecny tvar funkce:
%   WPAK2IM(C)
% 
%   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%   !!! Funkce slouzi pouze pro ukazku rozlozeni koeficientu           !!!
%   !!! transformace Wavelet Packet. Pri vypoctech dochazi v nekterych !!!
%   !!! pripadech k orezani okraju jednotlivych keoficientu a tedy     !!!
%   !!! zobrazeny obrazek neobsahuje vsechny koeficienty.              !!!
%   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% 



%% Urceni vhodnych rozmeru jednotlivych urovni
leng = length(c);
leng = uint8(leng);
for x = 2:leng                      % Urceni nejvyssi obsazene urovne 
    for uu = 1:length(c{x})         % v pripade zobrazeni CFS 
        if isempty(c{x}{uu}) == 0   % nejvyznamnejsich koeficientu
            siz{x} = size(c{x}{uu});
            break;
        end
    end
    if isempty(c{x}{uu}) ==0
            break;
    end
end
%= Zmenseni rozmeru do hodnoty delitelne beze zbytku do urovne LEVEL =%
for k = 1:2
  while mod(siz{x}(k),2^(leng-x)) 
     siz{x}(k) = siz{x}(k)-1;
  end
end
%================ Urceni rozmeru jednotlivych urovni =================%
for i = (x+1):leng
    for k = 1:2
        siz{i}(k) = siz{i-1}(k)/2;
    end
end
%====== "Orezani" rozmeru na jednotlivych urovnich dekompozice =======%
for i = x:leng
       for u = 1:length(c{i})
           if isempty(c{i}{u}) == 0
    c{i}{u} = c{i}{u}(end-siz{i}(1)+1:end,end-siz{i}(2)+1:end);
           end
       end
end
%=====================================================================%
%% Oramovani
for l = 0:1:leng-1
    len = length(c{end - l});
    for i = 1:len
        if isempty(c{end-l}{i}) == 0
            c{end-l}{i} = c{end-l}{i}/max(max(c{end-l}{i}));
            c{end-l}{i}(1,1:end) = ones;
            c{end-l}{i}(1:end,1) = ones;
            c{end-l}{i}(end,1:end) = ones;
            c{end-l}{i}(1:end,end) = ones;
        end
    end
end
%% Slozeni posledni urovne
len = length(c{end});
leng = length(c);
k = 0;
for i = 1:4:len-3
    k = k+1;
    if isempty(c{end}{i}) == 0
        dd{leng}{k} = [c{end}{i} c{end}{i+1};c{end}{i+2} c{end}{i+3}];
    else dd{leng}{k} = [];
    end
end

len = length(c{end-1});
for i = 1:len
    if isempty(dd{leng}{i}) == 1
        dd{leng-1}{i} = c{end-1}{i};
    else dd{leng-1}{i} = dd{leng}{i};
    end
end
%% Obsazeni ostatnich urovni
%========== Slozeni ctyr bunek predposledni urovne do jedne ==========%
k = 0;
for i = 1:4:len-3
    k = k+1;
    dd{leng-2}{k} = [dd{leng-1}{i} dd{leng-1}{i+1};dd{leng-1}{i+2} dd{leng-1}{i+3}];
%     if isempty(dd{leng-2}{k}) == 0
%         dd{leng-2}{k} = dd{leng-2}{k};
%     end
end
%=============== Slozeni bunek smerem k nejvyssi urovni ==============%
for  g = 2:leng-1
    len = length(c{end-g});
    k = 0;
    for i = 1:len
        if isempty(dd{leng-g}{i}) == 1
            if isempty(c{end-g}{i}) == 0;
                dd{leng-g}{i} = c{end-g}{i};
            end
        end
    end
    k = 0;
    for i = 1:4:len-3
        k = k+1;
        dd{leng-(g+1)}{k} = [dd{leng-g}{i} dd{leng-g}{i+1};dd{leng-g}{i+2} dd{leng-g}{i+3}];
    end 
end
figure;
imshow(im2uint8(dd{1}{1}));
% ee = im2uint8(dd{1}{1});