svr_dct_epsilon_distortion

PURPOSE ^

------------------------------------------------- --------------------------------------

SYNOPSIS ^

function Results = svr_dct_epsilon_distortion(Im,bits,parametro,epsilon_inicial,H,perfil,sepsigno,variable)

DESCRIPTION ^

 ------------------------------------------------- --------------------------------------
 SVR_dct calculates the rate-distortion curve for a picture (using
 constant tube until the cutoff frequency fc -en - cpd ).

 From a given distortion parameter (SNR , MSE , SSIM , MPE) it adjusts
 the value of epsilon SVR.
 Using this epsilon (and profile depending on the used algorithm),
 DCT blocks are trained (with a fixed C, and predefined profile and a 2D kernel
 variance 1).
 Finally , it calculates the entropy for the result.

 USAGE: [ Results] = svr_dct_2 (Im , bits, parameter, epsilon , H Profile, sepsigno , variable)

 Im         -> Image
 Bits         -> Number of bits for quantization of SVM weights
 Parameter     -> value parameter of distortion \ selected
 Epsilon     -> Initial value of epsilon
 H         -> Kernel used in SVR
 Profile     -> Profile epsilon for each frequency
 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 % ------------------------------------------------- --------------------------------------
0002 % SVR_dct calculates the rate-distortion curve for a picture (using
0003 % constant tube until the cutoff frequency fc -en - cpd ).
0004 %
0005 % From a given distortion parameter (SNR , MSE , SSIM , MPE) it adjusts
0006 % the value of epsilon SVR.
0007 % Using this epsilon (and profile depending on the used algorithm),
0008 % DCT blocks are trained (with a fixed C, and predefined profile and a 2D kernel
0009 % variance 1).
0010 % Finally , it calculates the entropy for the result.
0011 %
0012 % USAGE: [ Results] = svr_dct_2 (Im , bits, parameter, epsilon , H Profile, sepsigno , variable)
0013 %
0014 % Im         -> Image
0015 % Bits         -> Number of bits for quantization of SVM weights
0016 % Parameter     -> value parameter of distortion \ selected
0017 % Epsilon     -> Initial value of epsilon
0018 % H         -> Kernel used in SVR
0019 % Profile     -> Profile epsilon for each frequency
0020 % Sepsigno     -> Flag to account for the entropy of signs ( '1 ') or
0021 %         no ( '0 ')
0022 % Variable  -> Text string to select the distortion parameter.
0023 %
0024 % Results     -> Vector of struct containing information about the results
0025 %         for the given parameter of distortion :
0026 %         Struct ( 'bits ' bits, 'epsilon' , epsilon , 'NumNiv', NumNiv,
0027 %        'Image', ImR , 'Entropy', entropiat, 'Entropiasig', entropsn, 'entropiapes', entropcn)
0028 %         Results.SNR , Results.MSE , Results.SSIM , Results.MPE_lineal ,
0029 %         Results.MPE_no_lineal , Results.MPE_no_linea_JMLR
0030 
0031 function Results = svr_dct_epsilon_distortion(Im,bits,parametro,epsilon_inicial,H,perfil,sepsigno,variable)
0032 
0033 Lb = 16;
0034 Li = length(Im);
0035 
0036 R = 1:(Lb*Lb-1);
0037 R = R(:);
0038 N = length(R);
0039 
0040 C = 40000;
0041 D = ones(1,N);
0042 D = D(:);
0043 
0044 Results = [];
0045 ImR = rand(Li);
0046 
0047 switch(variable)
0048     case 'SNR', parametro_actual = 1; umbral = 0.5;
0049     case 'MSE', parametro_actual = 1; umbral = 0.1;
0050     case 'SSIM', parametro_actual = 0; umbral = 0.01;
0051     case 'MPE lineal', parametro_actual = 100; umbral = 0.01;
0052     case 'MPE no lineal', parametro_actual = 100; umbral = 0.01;
0053     case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.1;
0054 end
0055 
0056 epsilon = 0;
0057 
0058 iter = 0;
0059 
0060 porcentaje = 1;
0061 
0062 if(isequal(variable,'SSIM'))
0063     sentido = 0;
0064 else
0065     sentido = 1;
0066 end
0067 
0068 no_results = 0;
0069 
0070 l_min = 0;
0071 l_max = 100000;
0072 
0073 disp(['Adjustment of epsilon to reach desired ' variable ':   ' num2str(parametro)]);
0074 
0075 while((abs(parametro - parametro_actual) > umbral) & (iter < 30))
0076 
0077     iter = iter + 1;
0078     signoscoefs = [];
0079     betasc = [];
0080     BtC = [];
0081     Coef11 = [];
0082     SVs = [];
0083     lSVs = [];
0084 
0085     if(iter ~= 1 & iter ~= 2)
0086         switch(variable)
0087             case 'SNR',
0088                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0089             case 'MSE',
0090                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0091             case 'SSIM',
0092                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0093             case 'MPE lineal',
0094                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0095             case 'MPE no lineal',
0096                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0097             case 'MPE no lineal JMLR',
0098                 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0099         end
0100     end
0101 
0102     fprintf('Training all the blocks of the local DCT');
0103 
0104     for i = 1:Lb:Li
0105         fprintf('.');
0106         for j=1:Lb:Li
0107 
0108             B = Im(i:(i+(Lb-1)),j:(j+(Lb-1)));
0109             B = dct2(B);
0110             Coef11 = [Coef11;B(1,1)];
0111             B = zigzag(B);
0112             B = B(2:end);
0113             BtC = [BtC;B'];
0114 
0115             bitsig = getsign(B,Lb);
0116             signoscoefs = [signoscoefs; bitsig];
0117 
0118             [nsv,beta,bias] = irwls_pd_svr_nobias(R,abs(B),H,C,D,epsilon,perfil);
0119 
0120             betasc = [betasc;beta'];
0121         end
0122     end
0123 
0124     fprintf('\n');
0125 
0126     MM = max(max(abs(betasc)));
0127     MM=MM/4;
0128     NumNiv = 2^bits;
0129     betascr = round(NumNiv * betasc/MM)*MM/NumNiv;
0130     signos = zeros(size(signoscoefs));
0131     signos(logical(betascr~=0))=signoscoefs(logical(betascr~=0));
0132 
0133     z = 1;
0134     for i=1:Lb:Li
0135         for j=1:Lb:Li
0136 
0137             y = H*betascr(z,:)';
0138 
0139             y = obtainsign(y, signos, Lb,z);
0140             A = dezigzag([Coef11(z);y]);
0141             A = idct2(A);
0142             ImR(i:(i+(Lb-1)),j:(j+(Lb-1))) = A;
0143             z = z + 1;
0144         end
0145     end
0146 
0147     switch(variable)
0148         case 'SNR',
0149             [mse,SNRi] = emse2(Im,ImR);
0150             fprintf('   It. =
0151             parametro_actual = SNRi;
0152         case 'MSE',
0153             [mse,SNRi] = emse2(Im,ImR);
0154             fprintf('   It. =
0155             parametro_actual = mse;
0156         case 'SSIM',
0157             esesim = ssim_index(Im,ImR);
0158             fprintf('   It. =
0159             parametro_actual = esesim;
0160         case 'MPE lineal',
0161             [MSE,d_l,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(Im,ImR,2,[3 mean(mean(Im))],2,2);
0162             mpelin = d_l;
0163             fprintf('   It. =
0164             parametro_actual = mpelin;
0165         case 'MPE no lineal',
0166             [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],2,1,2,2);
0167             mpenonlin= d;
0168             fprintf('   It. =
0169             parametro_actual = mpenonlin;
0170         case 'MPE no lineal JMLR',
0171             [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],1,0.5,2,2);
0172             mpenonlinJMLR = d;
0173             fprintf('   It. =
0174             parametro_actual = mpenonlinJMLR;
0175     end
0176 
0177     if(~isequal(variable,'SSIM') & (iter == 1) & (parametro - parametro_actual < 0) & (epsilon == 0))
0178         no_results = 1;
0179         disp('No se puede ajustar el epsilon para este número de bits.');
0180         break;
0181 
0182     elseif(isequal(variable,'SSIM') & (iter == 1) & (parametro - parametro_actual > 0) & (epsilon == 0))
0183         no_results = 1;
0184         disp('No se puede ajustar el epsilon para este número de bits.');
0185         break;
0186 
0187     elseif((iter == 1) & (abs(parametro - parametro_actual) <= umbral) & (epsilon == 0))
0188 
0189         epsilon = epsilon_inicial;
0190 
0191         parametro_actual = 0;
0192 
0193     elseif(iter == 1)
0194         epsilon = epsilon_inicial;
0195     end
0196 end
0197 
0198 if(no_results == 0)
0199 
0200     entropc = [];
0201     entrops = [];
0202 
0203     codigon = betascr.*(~signos) - betascr.*(signos);
0204     for i=1:Lb^2
0205 
0206         if sepsigno==0
0207             codigo = betascr(i,:).*(~signos(i,:)) - betascr(i,:).*(signos(i,:));
0208             [rlePesos,repCeros] = rle2(codigo);
0209             entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0210             entrops = 0;
0211         else
0212 
0213             [rlePesos,repCeros] = rle2(betascr(i,:));
0214             entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0215 
0216             [rlePesoss,repCeross] = rle2(signos(i,:));
0217             entrops = [entrops length(rlePesoss)*entropiv(rlePesoss)+length(repCeross)*entropiv(repCeross)];
0218         end;
0219     end
0220 
0221     entropcn = sum(entropc)/Li^2;
0222     entropsn = sum(entrops)/Li^2;
0223 
0224     entropiat = entropcn + entropsn;
0225 
0226     Results = [Results; struct('bits',bits,'epsilon',epsilon,'NumNiv',NumNiv,'Image',ImR,'Entropy',entropiat, ...
0227         'entropiasig',entropsn,'entropiapes',entropcn)];
0228 
0229     switch(variable)
0230         case 'SNR',
0231             Results.SNR = SNRi;
0232         case 'MSE',
0233             Results.MSE = mse;
0234         case 'SSIM',
0235             Results.SSIM = esesim;
0236         case 'MPE lineal',
0237             Results.MPE_lineal = mpelin;
0238         case 'MPE no lineal',
0239             Results.MPE_no_lineal = mpenonlin;
0240         case 'MPE no lineal JMLR',
0241             Results.MPE_no_lineal_JMLR = mpenonlinJMLR;
0242     end
0243 end

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