svr_dct_epsilon_bits_fit_distortion

PURPOSE ^

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

SYNOPSIS ^

function Results = svr_dct_epsilon_bits_fit_distortion(Im,param,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         -> N number of bits for quantization of SVM weights
 Parameter     -> value pair 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 parameter of distortion
         in question

 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         -> N number of bits for quantization of SVM weights
0016 % Parameter     -> value pair 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 parameter of distortion
0023 %         in question
0024 %
0025 % Results     -> Vector of struct containing information about the results
0026 %         for the given parameter of distortion :
0027 %         Struct ( 'bits ' bits, 'epsilon' , epsilon , 'NumNiv', NumNiv,
0028 %        'Image', ImR , 'Entropy', entropiat, 'Entropiasig', entropsn, 'entropiapes', entropcn)
0029 %         Results.SNR , Results.MSE , Results.SSIM , Results.MPE_lineal ,
0030 %         Results.MPE_no_lineal , Results.MPE_no_linea_JMLR
0031 
0032 function Results = svr_dct_epsilon_bits_fit_distortion(Im,param,epsilon_inicial,H,perfil,sepsigno,variable)
0033 
0034 Lb = 16;
0035 Li = length(Im);
0036 
0037 R = 1:(Lb*Lb-1);
0038 R = R(:);
0039 N = length(R);
0040 
0041 C = 40000;
0042 D = ones(1,N);
0043 D = D(:);
0044 
0045 Results = [];
0046 ImR = rand(Li);
0047 
0048 contador = 0;
0049 
0050 ini_bits = 2;
0051 
0052 fin_bits = 8;
0053 
0054 for parametro = param
0055 
0056     disp(['Adjustment of epsilon to reach desired ' variable ':   ' num2str(parametro)]);
0057 
0058     contador = contador + 1;
0059 
0060     for bits = ini_bits:0.5:fin_bits
0061 
0062         switch(variable)
0063             case 'SNR', parametro_actual = 1; umbral = 0.05;
0064             case 'MSE', parametro_actual = 1; umbral = 0.5;
0065             case 'SSIM', parametro_actual = 0; umbral = 0.001;
0066             case 'MPE lineal', parametro_actual = 100; umbral = 0.01;
0067             case 'MPE no lineal', parametro_actual = 100; umbral = 0.01;
0068             case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.1;
0069         end
0070 
0071         epsilon = 0;
0072 
0073         iter = 0;
0074 
0075         porcentaje = 1;
0076 
0077         if(isequal(variable,'SSIM'))
0078             sentido = 0;
0079         else
0080             sentido = 1;
0081         end
0082 
0083         no_results = 0;
0084 
0085         l_min = 0;
0086         l_max = 100000;
0087 
0088         while((abs(parametro - parametro_actual) > umbral) & (iter < 30))
0089 
0090             iter = iter + 1;
0091             signoscoefs = [];
0092             betasc = [];
0093             BtC = [];
0094             Coef11 = [];
0095             SVs = [];
0096             lSVs = [];
0097 
0098             if(iter ~= 1 & iter ~= 2)
0099                 switch(variable)
0100                     case 'SNR',
0101                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0102                     case 'MSE',
0103                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0104                     case 'SSIM',
0105                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0106                     case 'MPE lineal',
0107                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0108                     case 'MPE no lineal',
0109                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0110                     case 'MPE no lineal JMLR',
0111                         [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro, parametro_actual, epsilon, l_min, l_max, porcentaje, sentido);
0112                 end
0113             end
0114 
0115             fprintf('Training all the blocks of the local DCT');
0116 
0117             for i = 1:Lb:Li
0118 
0119                 fprintf('.');
0120 
0121                 for j=1:Lb:Li
0122 
0123                     B = Im(i:(i+(Lb-1)),j:(j+(Lb-1)));
0124                     B = dct2(B);
0125                     Coef11 = [Coef11;B(1,1)];
0126                     B = zigzag(B);
0127                     B = B(2:end);
0128                     BtC = [BtC;B'];
0129 
0130                     bitsig = getsign(B,Lb);
0131                     signoscoefs = [signoscoefs; bitsig];
0132 
0133                     [nsv,beta,bias] = irwls_pd_svr_nobias(R,abs(B),H,C,D,epsilon,perfil);
0134 
0135                     betasc = [betasc;beta'];
0136 
0137                 end
0138             end
0139 
0140             fprintf('\n');
0141 
0142             MM = max(max(abs(betasc)));
0143             MM=MM/4;
0144             NumNiv = 2^bits;
0145             betascr = round(NumNiv * betasc/MM)*MM/NumNiv;
0146             signos = zeros(size(signoscoefs));
0147             signos(logical(betascr~=0))=signoscoefs(logical(betascr~=0));
0148 
0149             z = 1;
0150             for i=1:Lb:Li
0151                 for j=1:Lb:Li
0152 
0153                     y = H*betascr(z,:)';
0154 
0155                     y = obtainsign(y, signos, Lb,z);
0156                     A = dezigzag([Coef11(z);y]);
0157                     A = idct2(A);
0158                     ImR(i:(i+(Lb-1)),j:(j+(Lb-1))) = A;
0159                     z = z + 1;
0160                 end
0161             end
0162 
0163             switch(variable)
0164                 case 'SNR',
0165                     [mse,SNRi] = emse2(Im,ImR);
0166                     fprintf('   It. =
0167                     parametro_actual = SNRi;
0168                 case 'MSE',
0169                     [mse,SNRi] = emse2(Im,ImR);
0170                     fprintf('   It. =
0171                     parametro_actual = mse;
0172                 case 'SSIM',
0173                     esesim = ssim_index(Im,ImR);
0174                     fprintf('   It. =
0175                     parametro_actual = esesim;
0176                 case 'MPE lineal',
0177                     [MSE,d_l,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(Im,ImR,2,[3 mean(mean(Im))],2,2);
0178                     mpelin = d_l;
0179                     fprintf('   It. =
0180                     parametro_actual = mpelin;
0181                 case 'MPE no lineal',
0182                     [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],2,1,2,2);
0183                     mpenonlin= d;
0184                     fprintf('   It. =
0185                     parametro_actual = mpenonlin;
0186                 case 'MPE no lineal JMLR',
0187                     [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],1,0.5,2,2);
0188                     mpenonlinJMLR = d;
0189                     fprintf('   It. =
0190                     parametro_actual = mpenonlinJMLR;
0191             end
0192 
0193             if(~isequal(variable,'SSIM') & (iter == 1) & (param(contador) - parametro_actual < 0) & (epsilon == 0))
0194                 no_results = 1;
0195                 disp('No se puede ajustar el epsilon para este número de bits');
0196                 break;
0197 
0198             elseif(isequal(variable,'SSIM') & (iter == 1) & (param(contador) - parametro_actual > 0) & (epsilon == 0))
0199                 no_results = 1;
0200                 disp('No se puede ajustar el epsilon para este número de bits');
0201                 break;
0202 
0203             elseif((iter == 1) & (abs(param(contador) - parametro_actual) <= umbral) & (epsilon == 0))
0204                 no_results = 1;
0205                 disp('No se puede ajustar el epsilon para este número de bits');
0206                 break;
0207 
0208             elseif(iter == 1)
0209                 epsilon = epsilon_inicial;
0210             end
0211 
0212         end
0213 
0214         if(no_results == 0)
0215 
0216             entropc = [];
0217             entrops = [];
0218 
0219             codigon = betascr.*(~signos) - betascr.*(signos);
0220             for i=1:Lb^2
0221 
0222                 if sepsigno==0
0223                     codigo = betascr(i,:).*(~signos(i,:)) - betascr(i,:).*(signos(i,:));
0224                     [rlePesos,repCeros] = rle2(codigo);
0225                     entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0226                     entrops = 0;
0227                 else
0228 
0229                     [rlePesos,repCeros] = rle2(betascr(i,:));
0230                     entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0231 
0232                     [rlePesoss,repCeross] = rle2(signos(i,:));
0233                     entrops = [entrops length(rlePesoss)*entropiv(rlePesoss)+length(repCeross)*entropiv(repCeross)];
0234                 end;
0235             end
0236 
0237             entropcn = sum(entropc)/Li^2;
0238             entropsn = sum(entrops)/Li^2;
0239 
0240             entropiat = entropcn + entropsn;
0241 
0242             Results(contador).bits = bits;
0243             Results(contador).epsilon = epsilon;
0244             Results(contador).C = C;
0245             Results(contador).entropia = entropiat;
0246             Results(contador).Image = ImR;
0247             switch(variable)
0248                 case 'SNR',
0249                     Results(contador).SNR = SNRi;
0250                 case 'MSE',
0251                     Results(contador).MSE = mse;
0252                 case 'SSIM',
0253                     Results(contador).SSIM = esesim;
0254                 case 'MPE lineal',
0255                     Results(contador).MPE_lineal = mpelin;
0256                 case 'MPE no lineal',
0257                     Results(contador).MPE_no_lineal = mpenonlin;
0258                 case 'MPE no lineal JMLR',
0259                     Results(contador).MPE_no_lineal_JMLR = mpenonlinJMLR;
0260             end
0261 
0262             ini_bits = bits;
0263 
0264             break;
0265 
0266         end
0267     end
0268 end

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