svr_nl_epsilon_distortion

PURPOSE ^

SVR_NL DCTs 'retransformadas' of a 2D signal subblock

SYNOPSIS ^

function [Results] = svr_nl_epsilon_distortion(Im,bits,parametro,epsilon_inicial,K,exponente,sepsigno,variable)

DESCRIPTION ^

 SVR_NL DCTs 'retransformadas' of a 2D signal subblock
 (Currently 256 * 256 resolution 4)

 Difference of QDCT63_2 in allowing the introduction of a mask
 (16 * 16 ) selecting certain coefficients so that ,
 increased sequentially, you can simulate the progressive decoding
 (sending bits... : see progressive_coding.m ).
 This mask is introduced into the variable 'progres'.
 If progres = ones ( 16,16 ), the result is the same as using qdct63_2

 Difference of QDCT62 that allows you to not calculate the eigenvalues ​​of the original
 (if you're not interested, it saves time !)

 Represents QDCT62 signal in a domain with (approx.) statistically uncorrelated characteristics
 and uncorrelated perceptually (With perceptual metric identity).
 This is achieved through the divisive normalization: Teo & Heeger, Watson and Simoncelli.
 This transformation depends on its input signal ( state adaptation ).
 It has been shown that this type of response obtains independent statistics ( Simoncelli99 ) and
 perceptually ( Malo99 ) coefficients, and therefore is a suitable domain for
 a scalar quantizer.

 Since the perceptual metric in this domain is the identity apply uniform quantizers
 and flat bit-allocation per coefficient.

 For each block the invertibility is checked [max( eig ( D_R * h )) ], and the inverse is computed
 by using the analytical expression

 It is normalized to local Michaelson contrast and response according NAKA8.m :

 Norm = [1 1]................ Normalized by the average luminance
 of the subfield considered (local contrast).

 Norm = [3 Lm ]............... Normalized by the fixed value Lm (global contrast)
 the logical choice is to take Lm = mean ( mean ( Im) );
 ( Mean value in digital levels )


 Range to distribute the quantization levels in the domain response is given
 by the maximum diagonal gradient ( acting on contrasts, belonging to
 [ -1.1 ] ).

 USE: [Results] = svr_nl2(Im,bits,parametro,epsilon,K,exponente,sepsigno,variable)

 Im        -> Image to compress
 bits      -> Numerb of bits for the SVR weights quantization
 parametro -> Value parameter of distortion \ selected
 epsilon   -> Starting epsilon value
 K         -> SVR Kernel
 exponente -> Exponent for the nonlinearities
 sepsigno  -> Flag to account for the entropy of signs ( '1 ') or
         no ( '0 ')
 Variable  -> Text string to select the distortion parameter.

 Results     -> Vector of struct containing information about the results
         for the given parameter of distortion :
         Struct ( 'bits ' bits, 'epsilon' , epsilon , 'NumNiv', NumNiv,
        'Image', ImR , 'Entropy', entropiat, 'Entropiasig', entropsn, 'entropiapes', entropcn)
         Results.SNR , Results.MSE , Results.SSIM , Results.MPE_lineal ,
         Results.MPE_no_lineal , Results.MPE_no_linea_JMLR

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % SVR_NL DCTs 'retransformadas' of a 2D signal subblock
0002 % (Currently 256 * 256 resolution 4)
0003 %
0004 % Difference of QDCT63_2 in allowing the introduction of a mask
0005 % (16 * 16 ) selecting certain coefficients so that ,
0006 % increased sequentially, you can simulate the progressive decoding
0007 % (sending bits... : see progressive_coding.m ).
0008 % This mask is introduced into the variable 'progres'.
0009 % If progres = ones ( 16,16 ), the result is the same as using qdct63_2
0010 %
0011 % Difference of QDCT62 that allows you to not calculate the eigenvalues ​​of the original
0012 % (if you're not interested, it saves time !)
0013 %
0014 % Represents QDCT62 signal in a domain with (approx.) statistically uncorrelated characteristics
0015 % and uncorrelated perceptually (With perceptual metric identity).
0016 % This is achieved through the divisive normalization: Teo & Heeger, Watson and Simoncelli.
0017 % This transformation depends on its input signal ( state adaptation ).
0018 % It has been shown that this type of response obtains independent statistics ( Simoncelli99 ) and
0019 % perceptually ( Malo99 ) coefficients, and therefore is a suitable domain for
0020 % a scalar quantizer.
0021 %
0022 % Since the perceptual metric in this domain is the identity apply uniform quantizers
0023 % and flat bit-allocation per coefficient.
0024 %
0025 % For each block the invertibility is checked [max( eig ( D_R * h )) ], and the inverse is computed
0026 % by using the analytical expression
0027 %
0028 % It is normalized to local Michaelson contrast and response according NAKA8.m :
0029 %
0030 % Norm = [1 1]................ Normalized by the average luminance
0031 % of the subfield considered (local contrast).
0032 %
0033 % Norm = [3 Lm ]............... Normalized by the fixed value Lm (global contrast)
0034 % the logical choice is to take Lm = mean ( mean ( Im) );
0035 % ( Mean value in digital levels )
0036 %
0037 %
0038 % Range to distribute the quantization levels in the domain response is given
0039 % by the maximum diagonal gradient ( acting on contrasts, belonging to
0040 % [ -1.1 ] ).
0041 %
0042 % USE: [Results] = svr_nl2(Im,bits,parametro,epsilon,K,exponente,sepsigno,variable)
0043 %
0044 % Im        -> Image to compress
0045 % bits      -> Numerb of bits for the SVR weights quantization
0046 % parametro -> Value parameter of distortion \ selected
0047 % epsilon   -> Starting epsilon value
0048 % K         -> SVR Kernel
0049 % exponente -> Exponent for the nonlinearities
0050 % sepsigno  -> Flag to account for the entropy of signs ( '1 ') or
0051 %         no ( '0 ')
0052 % Variable  -> Text string to select the distortion parameter.
0053 %
0054 % Results     -> Vector of struct containing information about the results
0055 %         for the given parameter of distortion :
0056 %         Struct ( 'bits ' bits, 'epsilon' , epsilon , 'NumNiv', NumNiv,
0057 %        'Image', ImR , 'Entropy', entropiat, 'Entropiasig', entropsn, 'entropiapes', entropcn)
0058 %         Results.SNR , Results.MSE , Results.SSIM , Results.MPE_lineal ,
0059 %         Results.MPE_no_lineal , Results.MPE_no_linea_JMLR
0060 
0061 function [Results] = svr_nl_epsilon_distortion(Im,bits,parametro,epsilon_inicial,K,exponente,sepsigno,variable)
0062 
0063 MM = 0.8;
0064 normaliz = [3 mean(mean(Im))];
0065 cero = 1;
0066 
0067 bloques = [];
0068 for i = 1:16
0069     for j = 1:16
0070         bloques = [bloques;i j];
0071     end
0072 end
0073 
0074 [h,alpha,beta,gamm] = constrains_resp(exponente,cero);
0075 
0076 Ncuan = 4;
0077 tam = size(Im);
0078 tam = tam(1);
0079 lados = [tam tam];
0080 lcuan = tam/(2^Ncuan);
0081 
0082 posai = [tam tam]/2-round(tam/2);
0083 posbd = [tam tam]/2+round(tam/2);
0084 coorcuanai = floor([(posai(1)-1)/lcuan+1 (posai(2)-1)/lcuan+1]);
0085 coorcuanbd = floor([(posbd(1)-1)/lcuan+1 (posbd(2)-1)/lcuan+1]);
0086 if coorcuanai(1) < 1
0087     coorcuanai(1) = 1;
0088 end
0089 if coorcuanai(2) < 1
0090     coorcuanai(2) = 1;
0091 end
0092 if coorcuanbd(1) > (2^Ncuan)
0093     coorcuanbd(1) = 2^Ncuan;
0094 end
0095 if coorcuanai(2) > (2^Ncuan)
0096     coorcuanbd(2) = 2^Ncuan;
0097 end
0098 
0099 dcti = dct2r(Im,Ncuan);
0100 [dct_contr,Lm] = contras2(dcti,Ncuan,normaliz);
0101 DC = Lm*16;
0102 
0103 dctc1 = zeros(tam,tam);
0104 
0105 codigo = [];
0106 nceros = [];
0107 
0108 R = (1:255);R=R(:);
0109 
0110 C = 40000;
0111 perfil_C = ones(255,1);
0112 
0113 perfil_e = ones(255,1);
0114 
0115 Lb = lcuan;
0116 Li = tam;
0117 
0118 Results = [];
0119 ImR = rand(Li);
0120 iter = 0;
0121 
0122 switch(variable)
0123     case 'SNR', parametro_actual = 1; umbral = 0.5;
0124     case 'MSE', parametro_actual = 1; umbral = 0.5;
0125     case 'SSIM', parametro_actual = 0; umbral = 0.01;
0126     case 'MPE lineal', parametro_actual = 100; umbral = 0.05;
0127     case 'MPE no lineal', parametro_actual = 100; umbral = 0.05;
0128     case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.05;
0129 end
0130 
0131 epsilon = 0;
0132 
0133 iter = 0;
0134 
0135 porcentaje = 1;
0136 
0137 if(isequal(variable,'SSIM'))
0138     sentido = 0;
0139 else
0140     sentido = 1;
0141 end
0142 
0143 no_results = 0;
0144 
0145 l_min = 0;
0146 l_max = 100000;
0147 
0148 disp(['Adjustment of epsilon to reach desired ' variable ':   ' num2str(parametro)]);
0149 
0150 while (abs(parametro - parametro_actual) > umbral) & (iter < 30)
0151 
0152     iter = iter + 1;
0153     dctc1 = zeros(tam,tam);
0154     dctsincuant = dctc1;
0155     signosr = [];
0156     betasc = [];
0157     betascr = [];
0158     dctc1i = [];
0159 
0160     if(iter ~= 1 & iter ~= 2)
0161         switch(variable)
0162             case 'SNR',
0163                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0164             case 'MSE',
0165                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0166             case 'SSIM',
0167                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0168             case 'MPE lineal',
0169                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0170             case 'MPE no lineal',
0171                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0172             case 'MPE no lineal JMLR',
0173                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0174         end
0175     end
0176 
0177     fprintf('  Training all the blocks of the local non-linear domain');
0178 
0179     for i = 1:Lb:Li
0180         fprintf('.');
0181         for j = 1:Lb:Li
0182 
0183             aa = dct_contr(i:(i+(Lb-1)),j:(j+(Lb-1)));
0184 
0185             [h_a,r,GR,alfa2d,beta2d] = respue5(aa,alpha,beta,gamm,h,0);
0186 
0187             r = zigzag(r);
0188 
0189             [nsv,pesosSVM,bias] = irwls_pd_svr_nobias(R,r(2:256),K,C,perfil_C,epsilon,perfil_e);
0190 
0191             azig = zigzag(aa);
0192             azigsc = azig(2:end);
0193 
0194             bitsig = getsign(azigsc,Lb);
0195             signosr = [signosr; bitsig];
0196             betasc = [betasc;pesosSVM'];
0197         end
0198     end
0199     fprintf('\n');
0200 
0201     NumNiv = 2^bits;
0202 
0203     betascr = round( NumNiv * betasc/MM)*MM/NumNiv;
0204 
0205     rc = [];
0206     for fila = 1:Li
0207         rc = [rc; (K*betascr(fila,:)')'];
0208     end
0209 
0210     signos = zeros(size(signosr));
0211     signos(logical(abs(rc)>0)) = signosr(logical(abs(rc)>0));
0212 
0213     fprintf('Recovering the image:\n');
0214     fprintf('  Inverting from r to dct\n');
0215 
0216     z = 1;
0217     DC = DC';
0218     DC = DC(:);
0219 
0220     Db = diag(beta2d);
0221     Identidad = eye(size(h));
0222 
0223     for i = 1:Lb:(Li-1)
0224         for j = 1:Lb:(Li-1)
0225 
0226             r_recon = K*betascr(z,:)';
0227 
0228             r_recon = [0; r_recon];
0229 
0230             Dr = diag(r_recon);
0231 
0232             ac = ((inv(Identidad-Dr*h)*Db*r_recon).^(1/gamm))./alfa2d;
0233 
0234             ac1 = obtainsign(ac(2:end), signos, Lb,z);
0235             ac1 = [0;ac1];
0236 
0237             ac1 = dezigzag(ac1);
0238 
0239             ac1(1,1) = DC(z);
0240 
0241             dctc1(i:(i+(Lb-1)),j:(j+(Lb-1))) = ac1;
0242 
0243             z = z+1;
0244         end
0245     end
0246 
0247     fprintf('  Inverting from dct to spatial domain\n');
0248 
0249     dctc1i = icontra2(dctc1,Lm,4,normaliz);
0250     ImR = real(idct2r(dctc1i,4));
0251 
0252     switch(variable)
0253         case 'SNR',
0254             [mse,SNRi] = emse2(Im,ImR);
0255             fprintf('   It. =
0256             parametro_actual = SNRi;
0257         case 'MSE',
0258             [mse,SNRi] = emse2(Im,ImR);
0259             fprintf('   It. =
0260             parametro_actual = mse;
0261         case 'SSIM',
0262             esesim = ssim_index(Im,ImR);
0263             fprintf('   It. =
0264             parametro_actual = esesim;
0265         case 'MPE lineal',
0266             [MSE,d_l,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(Im,ImR,2,[3 mean(mean(Im))],2,2);
0267             mpelin = d_l;
0268             fprintf('   It. =
0269             parametro_actual = mpelin;
0270         case 'MPE no lineal',
0271             [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],2,1,2,2);
0272             mpenonlin= d;
0273             fprintf('   It. =
0274             parametro_actual = mpenonlin;
0275         case 'MPE no lineal JMLR',
0276             [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],1,0.5,2,2);
0277             mpenonlinJMLR = d;
0278             fprintf('   It. =
0279             parametro_actual = mpenonlinJMLR;
0280     end
0281 
0282     if(~isequal(variable,'SSIM') & (iter == 1) & (parametro - parametro_actual < 0) & (epsilon == 0))
0283         no_results = 1;
0284         disp('No se puede ajustar el epsilon para este número de bits.');
0285         break;
0286 
0287     elseif(isequal(variable,'SSIM') & (iter == 1) & (parametro - parametro_actual > 0) & (epsilon == 0))
0288         no_results = 1;
0289         disp('No se puede ajustar el epsilon para este número de bits.');
0290         break;
0291 
0292     elseif((iter == 1) & (abs(parametro - parametro_actual) <= umbral) & (epsilon == 0))
0293 
0294         epsilon = epsilon_inicial;
0295 
0296         parametro_actual = 0;
0297 
0298     elseif(iter == 1)
0299         epsilon = epsilon_inicial;
0300     end
0301 
0302 end
0303 
0304 if(no_results == 0)
0305 
0306     entropc = [];
0307     entrops = [];
0308 
0309     codigon = betascr.*(~signos) - betascr.*(signos);
0310     for i = 1:Lb^2
0311 
0312         if sepsigno == 0
0313             codigo = betascr(i,:).*(~signos(i,:)) - betascr(i,:).*(signos(i,:));
0314             [rlePesos,repCeros] = rle2(codigo);
0315             entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0316             entrops = 0;
0317         else
0318 
0319             [rlePesos,repCeros] = rle2(betascr(i,:));
0320             entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0321 
0322             [rlePesoss,repCeross] = rle2(signos(i,:));
0323             entrops = [entrops length(rlePesoss)*entropiv(rlePesoss)+length(repCeross)*entropiv(repCeross)];
0324         end;
0325 
0326     end
0327 
0328     entropcn = sum(entropc)/Li^2;
0329     entropsn = sum(entrops)/Li^2;
0330 
0331     entropiat = entropcn + entropsn
0332 
0333     Results = [Results; struct('bits',bits,'epsilon',epsilon,'NumNiv',NumNiv,'Image',ImR,'Entropy',entropiat,...
0334         'entropiasig',entropsn,'entropiapes',entropcn)];
0335 
0336     switch(variable)
0337         case 'SNR',
0338             Results.SNR = SNRi;
0339         case 'MSE',
0340             Results.MSE = mse;
0341         case 'SSIM',
0342             Results.SSIM = esesim;
0343         case 'MPE lineal',
0344             Results.MPE_lineal = mpelin;
0345         case 'MPE no lineal',
0346             Results.MPE_no_lineal = mpenonlin;
0347         case 'MPE no lineal JMLR',
0348             Results.MPE_no_lineal_JMLR = mpenonlinJMLR;
0349     end
0350 end

Generated on Fri 07-Mar-2014 13:29:20 by m2html © 2005