svr_dct_epsilon_bits_distortion

PURPOSE ^

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

SYNOPSIS ^

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

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