function [x,a,b] = synthese(g0,g1,x,a,b,niv,s)
%        [x,a,b] = synthese(g0,g1,x,a,b,niv,s)
% x = synthese des sous images de l'analyse
% effectuee au niveau niv (sx), 1 <= niv <= 4
% extension sym. pour filtres sym. g0 et g1
% decompression et dequantification sauf pour x00
% a,b: affinite a*x+b sur sous-image sx de x
% s = parametre optionnel,  s = 'v' pour voir les
% sous-images, s = 'c' pour les compresser
%------------------------------------------------

if (niv < 1) | (niv > 4)
 error('niveau incorrect');
end

[nl,nc] = size(x);
for i=1:niv-1
 nl = ceil(nl/2); nc = ceil(nc/2);
end
sx = x(1:nl,1:nc);

l1 = floor(nl/2); l0 = nl-l1;
c1 = floor(nc/2); c0 = nc-c1;

x00 = sx(1:l0,1:c0);
x01 = sx(l0+1:nl,1:c0);
x10 = sx(1:l0,c0+1:nc);
x11 = sx(l0+1:nl,c0+1:nc);

sa = a(1:2,1:2); sb = b(1:2,1:2);
a(:,1:2) = []; b(:,1:2) = [];

a01 = sa(2,1); a10 = sa(1,2); a11 = sa(2,2);
b01 = sb(2,1); b10 = sb(1,2); b11 = sb(2,2);

%------------------------------------------------
% dequantification, interpolation des colonnes
% et filtrage des colonnes
%------------------------------------------------

x01 = dequant(x01,a01,b01,s); 
x10 = dequant(x10,a10,b10,s); 
x11 = dequant(x11,a11,b11,s); 

z = zeros(nl,c0); z(1:2:nl,:) = x00; x00 = z;
z = zeros(nl,c0); z(2:2:nl,:) = x01; x01 = z;
z = zeros(nl,c1); z(1:2:nl,:) = x10; x10 = z;
z = zeros(nl,c1); z(2:2:nl,:) = x11; x11 = z;

x00 = filtre(g0,x00);
x01 = filtre(g1,x01);
x10 = filtre(g0,x10);
x11 = filtre(g1,x11);

x0 = x00+x01;
x1 = x10+x11;

%------------------------------------------------
% interpolation des lignes et filtrage lignes
%------------------------------------------------

z = zeros(nl,nc); z(:,1:2:nc) = x0; x0 = z;
z = zeros(nl,nc); z(:,2:2:nc) = x1; x1 = z;

x0 = filtre(g0,x0')';
x1 = filtre(g1,x1')';

sx = x0+x1;
x(1:nl,1:nc) = sx;
