svr_nl_epsilon_bits_fit_distortion

PURPOSE ^

SVR_NL DCTs 'retransformadas' of a 2D signal subblock

SYNOPSIS ^

function [Results] = svr_nl_epsilon_bits_fit_distortion(Im,param,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_bits_fit_distortion(Im,param,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 
0121 contador = 0;
0122 
0123 ini_bits = 2;
0124 
0125 fin_bits = 15;
0126 
0127 for parametro = param
0128 
0129     disp(['Adjustment of epsilon to reach desired ' variable ':   ' num2str(parametro)]);
0130 
0131     contador = contador + 1;
0132 
0133     for bits = ini_bits:0.5:fin_bits
0134 
0135         switch(variable)
0136             case 'SNR', parametro_actual = 1; umbral = 0.05;
0137             case 'MSE', parametro_actual = 1; umbral = 0.5;
0138             case 'SSIM', parametro_actual = 0; umbral = 0.001;
0139             case 'MPE lineal', parametro_actual = 100; umbral = 0.01;
0140             case 'MPE no lineal', parametro_actual = 100; umbral = 0.01;
0141             case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.1;
0142         end
0143 
0144         epsilon = 0;
0145 
0146         iter = 0;
0147 
0148         porcentaje = 1;
0149 
0150         if(isequal(variable,'SSIM'))
0151             sentido = 0;
0152         else
0153             sentido = 1;
0154         end
0155 
0156         no_results = 0;
0157 
0158         l_min = 0;
0159         l_max = 100;
0160 
0161         while (abs(parametro - parametro_actual) > umbral) & (iter < 30)
0162 
0163             iter = iter + 1;
0164             dctc1 = zeros(tam,tam);
0165             dctsincuant = dctc1;
0166             signosr = [];
0167             betasc = [];
0168             betascr = [];
0169             dctc1i = [];
0170 
0171             if(iter ~= 1 & iter ~= 2)
0172                 switch(variable)
0173                     case 'SNR',
0174                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0175                     case 'MSE',
0176                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0177                     case 'SSIM',
0178                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0179                     case 'MPE lineal',
0180                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0181                     case 'MPE no lineal',
0182                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0183                     case 'MPE no lineal JMLR',
0184                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0185                 end
0186             end
0187 
0188             fprintf('  Training all the blocks of the local non-linear domain');
0189 
0190             for i = 1:Lb:Li
0191                 fprintf('.');
0192                 for j = 1:Lb:Li
0193 
0194                     aa = dct_contr(i:(i+(Lb-1)),j:(j+(Lb-1)));
0195 
0196                     [h_a,r,GR,alfa2d,beta2d] = respue5(aa,alpha,beta,gamm,h,0);
0197 
0198                     r = zigzag(r);
0199 
0200                     [nsv,pesosSVM,bias] = irwls_pd_svr_nobias(R,r(2:256),K,C,perfil_C,epsilon,perfil_e);
0201 
0202                     azig = zigzag(aa);
0203                     azigsc = azig(2:end);
0204 
0205                     bitsig = getsign(azigsc,Lb);
0206                     signosr = [signosr; bitsig];
0207                     betasc = [betasc;pesosSVM'];
0208 
0209                 end
0210             end
0211 
0212             fprintf('\n');
0213 
0214             NumNiv = 2^bits;
0215 
0216             betascr = round( NumNiv * betasc/MM)*MM/NumNiv;
0217 
0218             rc = [];
0219             for fila = 1:Li
0220                 rc = [rc; (K*betascr(fila,:)')'];
0221             end
0222 
0223             signos = zeros(size(signosr));
0224             signos(logical(abs(rc)>0)) = signosr(logical(abs(rc)>0));
0225 
0226             fprintf('Recovering the image:\n');
0227             fprintf('  Inverting from r to dct\n');
0228 
0229             z = 1;
0230             DC = DC';
0231             DC = DC(:);
0232 
0233             Db = diag(beta2d);
0234             Identidad = eye(size(h));
0235 
0236             for i = 1:Lb:(Li-1)
0237                 for j = 1:Lb:(Li-1)
0238 
0239                     r_recon = K*betascr(z,:)';
0240 
0241                     r_recon = [0; r_recon];
0242 
0243                     Dr = diag(r_recon);
0244 
0245                     ac = ((inv(Identidad-Dr*h)*Db*r_recon).^(1/gamm))./alfa2d;
0246 
0247                     ac1 = obtainsign(ac(2:end), signos, Lb,z);
0248                     ac1 = [0;ac1];
0249 
0250                     ac1 = dezigzag(ac1);
0251 
0252                     ac1(1,1) = DC(z);
0253 
0254                     dctc1(i:(i+(Lb-1)),j:(j+(Lb-1))) = ac1;
0255 
0256                     z = z+1;
0257                 end
0258             end
0259 
0260             fprintf('  Inverting from dct to spatial domain\n');
0261 
0262             dctc1i = icontra2(dctc1,Lm,4,normaliz);
0263             ImR = real(idct2r(dctc1i,4));
0264 
0265             switch(variable)
0266                 case 'SNR',
0267                     [mse,SNRi] = emse2(Im,ImR);
0268                     fprintf('   It. =
0269                     parametro_actual = SNRi;
0270                 case 'MSE',
0271                     [mse,SNRi] = emse2(Im,ImR);
0272                     fprintf('   It. =
0273                     parametro_actual = mse;
0274                 case 'SSIM',
0275                     esesim = ssim_index(Im,ImR);
0276                     fprintf('   It. =
0277                     parametro_actual = esesim;
0278                 case 'MPE lineal',
0279                     [MSE,d_l,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(Im,ImR,2,[3 mean(mean(Im))],2,2);
0280                     mpelin = d_l;
0281                     fprintf('   It. =
0282                     parametro_actual = mpelin;
0283                 case 'MPE no lineal',
0284                     [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],2,1,2,2);
0285                     mpenonlin= d;
0286                     fprintf('   It. =
0287                     parametro_actual = mpenonlin;
0288                 case 'MPE no lineal JMLR',
0289                     [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],1,0.5,2,2);
0290                     mpenonlinJMLR = d;
0291                     fprintf('   It. =
0292                     parametro_actual = mpenonlinJMLR;
0293             end
0294 
0295             if(~isequal(variable,'SSIM') & (iter == 1) & (param(contador) - parametro_actual < 0) & (epsilon == 0))
0296                 no_results = 1;
0297                 disp('No se puede ajustar el epsilon para este número de bits');
0298                 break;
0299 
0300             elseif(isequal(variable,'SSIM') & (iter == 1) & (param(contador) - parametro_actual > 0) & (epsilon == 0))
0301                 no_results = 1;
0302                 disp('No se puede ajustar el epsilon para este número de bits');
0303                 break;
0304 
0305             elseif((iter == 1) & (abs(param(contador) - parametro_actual) <= umbral) & (epsilon == 0))
0306                 no_results = 1;
0307                 disp('No se puede ajustar el epsilon para este número de bits');
0308                 break;
0309 
0310             elseif(iter == 1)
0311                 epsilon = epsilon_inicial;
0312             end
0313 
0314         end
0315 
0316         if(no_results == 0)
0317 
0318             entropc = [];
0319             entrops = [];
0320 
0321             codigon = betascr.*(~signos) - betascr.*(signos);
0322             for i = 1:Lb^2
0323 
0324                 if sepsigno == 0
0325                     codigo = betascr(i,:).*(~signos(i,:)) - betascr(i,:).*(signos(i,:));
0326                     [rlePesos,repCeros] = rle2(codigo);
0327                     entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0328                     entrops = 0;
0329                 else
0330 
0331                     [rlePesos,repCeros] = rle2(betascr(i,:));
0332                     entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0333 
0334                     [rlePesoss,repCeross] = rle2(signos(i,:));
0335                     entrops = [entrops length(rlePesoss)*entropiv(rlePesoss)+length(repCeross)*entropiv(repCeross)];
0336                 end;
0337 
0338             end
0339 
0340             entropcn = sum(entropc)/Li^2;
0341             entropsn = sum(entrops)/Li^2;
0342 
0343             entropiat = entropcn + entropsn;
0344 
0345             Results(contador).bits = bits;
0346             Results(contador).epsilon = epsilon;
0347             Results(contador).C = C;
0348             Results(contador).entropia = entropiat;
0349             Results(contador).Image = ImR;
0350 
0351             switch(variable)
0352                 case 'SNR',
0353                     Results(contador).SNR = SNRi;
0354                 case 'MSE',
0355                     Results(contador).MSE = mse;
0356                 case 'SSIM',
0357                     Results(contador).SSIM = esesim;
0358                 case 'MPE lineal',
0359                     Results(contador).MPE_lineal = mpelin;
0360                 case 'MPE no lineal',
0361                     Results(contador).MPE_no_lineal = mpenonlin;
0362                 case 'MPE no lineal JMLR',
0363                     Results(contador).MPE_no_lineal_JMLR = mpenonlinJMLR;
0364             end
0365 
0366             ini_bits = bits;
0367 
0368             break;
0369         end
0370     end
0371 end

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