function x = pdfbrec(y, pfilt, dfilt)
% PDFBREC   Smerova Pyramidova banka filtru
%
%	x = pdfbrec(y, pfilt, dfilt)
%
% Vstup:
%   y:	    buňka vektoru délky n +1, jeden pro každou vrstvu subpásmových
%   obrazu z DFB, y {1} je dolní pasmo obrazku
%   pfilt:  typ pyramidoveho filtru
%   dfilt:  typ smeroveho filtru
% Vystup:
%   x:      rekonstruovany obraz
%
% dalsi funkce: PFILTERS, DFILTERS, PDFBDEC

n = length(y) - 1;
if n <= 0
    x = y{1};
    
else
    % rekurzivni volani
    xlo = pdfbrec(y(1:end-1), pfilt, dfilt);
    
    % Get the pyramidal filters from the filter name
    [h, g] = pfilters(pfilt);
    
    % Process the detail subbands
    if length(y{end}) ~= 3
        % Reconstruct the bandpass image from DFB
        
        % Decide the method based on the filter name
        switch dfilt        
            case {'pkva6', 'pkva8', 'pkva12', 'pkva'}	
                % Use the ladder structure (much more efficient)
                xhi = dfbrec_l(y{end}, dfilt);
                
            otherwise	
                % General case
                xhi = dfbrec(y{end}, dfilt); 
        end
        
        x = lprec(xlo, xhi, h, g);
   
    else    
        % Special case: length(y{end}) == 3
        % Perform one-level 2-D critically sampled wavelet filter bank
        x = wfb2rec(xlo, y{end}{1}, y{end}{2}, y{end}{3}, h, g);
    end
end