distortion_svr

PURPOSE ^

Given a value for a distortion (RMSE o SSIM) it iterates to reach

SYNOPSIS ^

function [Results] = distortion_svr(algoritmo,variable,distorsiones,Im,epsilon_ini,K,perfil,exponente,directorio)

DESCRIPTION ^

 Given a value for a distortion (RMSE o SSIM) it iterates to reach
 an image with this distortion.
 It encodes the image, gets a  "ristra" and decodes the image using
 the nl+svr algorithm.
 It computes the distortion and reset the epsilon parameter if necessary,
 and starts again.
 It gives back an struct with the encoder results and the decoded image.

 NOTE THAT: The distortion values vector has to be sorted descent for all the
 distortions but for the SSIM, which will sort in ascent.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 % Given a value for a distortion (RMSE o SSIM) it iterates to reach
0003 % an image with this distortion.
0004 % It encodes the image, gets a  "ristra" and decodes the image using
0005 % the nl+svr algorithm.
0006 % It computes the distortion and reset the epsilon parameter if necessary,
0007 % and starts again.
0008 % It gives back an struct with the encoder results and the decoded image.
0009 %
0010 % NOTE THAT: The distortion values vector has to be sorted descent for all the
0011 % distortions but for the SSIM, which will sort in ascent.
0012 function [Results] = distortion_svr(algoritmo,variable,distorsiones,Im,epsilon_ini,K,perfil,exponente,directorio)
0013 N = length(Im);
0014 
0015 ini_bits = 2.5;
0016 fin_bits = 15;
0017 for i = 1:length(distorsiones)
0018 
0019     ImR = [];
0020     disp(['Ajustando el epsilon para hallar el ' variable ' de:   ' num2str(distorsiones(i))]);
0021     for b = ini_bits:0.5:fin_bits
0022         switch(variable)
0023             case 'RMSE', distorsion_actual = 0; umbral = 0.01;
0024             case 'SSIM', distorsion_actual = 0; umbral = 0.001;
0025             case 'MPE lineal', distorsion_actual = 100; umbral = 0.01;
0026             case 'MPE no lineal', distorsion_actual = 100; umbral = 0.01;
0027             case 'MPE no lineal JMLR', distorsion_actual = 100; umbral = 0.1;
0028         end
0029 
0030         epsilon = 0;
0031 
0032         bits = b;
0033 
0034         iter = 0;
0035 
0036         porcentaje = 1;
0037 
0038         if(isequal(variable,'SSIM'))
0039             sentido = 0;
0040         else
0041             sentido = 1;
0042         end
0043 
0044         l_min = 0;
0045         l_max = 100000;
0046 
0047         no_results = 0;
0048         while((abs(distorsiones(i) - distorsion_actual) > umbral) & (iter < 30))
0049             iter = iter + 1;
0050 
0051             if(iter ~= 1 & iter ~= 2)
0052                 if(isequal(variable,'SSIM'))
0053                     [epsilon,l_min,l_max,porcentaje,sentido] = fitting_epsilon_SSIM(distorsiones(i),distorsion_actual,epsilon,l_min,l_max,porcentaje,sentido);
0054                 else
0055                     [epsilon,l_min,l_max,porcentaje,sentido] = fitting_epsilon(distorsiones(i),distorsion_actual,epsilon,l_min,l_max,porcentaje,sentido);
0056                 end
0057             end
0058 
0059             switch(algoritmo)
0060                 case 1,
0061                     fichero = 'cte_svr_distorsion';
0062                     svr_dct_encoder(Im,bits,epsilon,K,perfil,directorio,[fichero '_' num2str(i)]);
0063                 case 2,
0064                     fichero = 'rki_svr_distorsion';
0065                     svr_dct_encoder(Im,bits,epsilon,K,perfil,directorio,[fichero '_' num2str(i)]);
0066                 case 3,
0067                     fichero = 'csf_svr_distorsion';
0068                     svr_dct_encoder(Im,bits,epsilon,K,perfil,directorio,[fichero '_' num2str(i)]);
0069                 case 4,
0070                     fichero = 'nl1_svr_distorsion';
0071                     svr_nl_encoder(Im,bits,epsilon,K,exponente,directorio,[fichero '_' num2str(i)]);
0072                 case 5,
0073                     fichero = 'nl2_svr_distorsion';
0074                     svr_nl_encoder(Im,bits,epsilon,K,exponente,directorio,[fichero '_' num2str(i)]);
0075             end
0076 
0077             switch(algoritmo)
0078                 case 1,
0079                     [ImR] = svr_dct_decoder(K,directorio,[fichero '_' num2str(i)]);
0080                 case 2,
0081                     [ImR] = svr_dct_decoder(K,directorio,[fichero '_' num2str(i)]);
0082                 case 3,
0083                     [ImR] = svr_dct_decoder(K,directorio,[fichero '_' num2str(i)]);
0084                 case 4,
0085                     [ImR] = svr_nl_decoder(K,exponente,directorio,[fichero '_' num2str(i)]);
0086                 case 5,
0087                     [ImR] = svr_nl_decoder(K,exponente,directorio,[fichero '_' num2str(i)]);
0088             end
0089 
0090             switch(variable)
0091                 case 'RMSE',
0092                     [mse,SNRi] = emse2(double(Im),ImR);
0093                     distorsion_actual = sqrt(mse);
0094                 case 'SSIM',
0095                     esesim = ssim_index(double(Im),ImR);
0096                     distorsion_actual = esesim;
0097                 case 'MPE lineal',
0098                     [MSE,MPEl,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(double(Im),ImR,2,[3 mean(mean(Im))],2,2);
0099                     distorsion_actual = MPEl;
0100                 case 'MPE no lineal',
0101                     [MSE,MPEnl,dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im),ImR,[3 mean(mean(Im))],2,1,2,2);
0102                     distorsion_actual = MPEnl;
0103                 case 'MPE no lineal JMLR',
0104                     [MSE,MPEnlJMLR,dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im),ImR,[3 mean(mean(Im))],1,0.5,2,2);
0105                     distorsion_actual = MPEnlJMLR;
0106             end
0107             disp(['Iteracion:  ' num2str(iter) '   ' variable ':  ' num2str(distorsion_actual) '   bits:  ' num2str(bits) '   epsilon:  ' num2str(epsilon)]);
0108 
0109             if(~isequal(variable,'SSIM') & (iter == 1) & (distorsiones(i) - distorsion_actual < 0) & (epsilon == 0))
0110                 no_results = 1;
0111                 disp('No se puede ajustar el epsilon para este número de bits.');
0112                 break;
0113 
0114             elseif(isequal(variable,'SSIM') & (iter == 1) & (distorsiones(i) - distorsion_actual > 0) & (epsilon == 0))
0115                 no_results = 1;
0116                 disp('No se puede ajustar el epsilon para este número de bits.');
0117                 break;
0118 
0119             elseif((iter == 1) & (abs(distorsiones(i) - distorsion_actual) <= umbral) & (epsilon == 0))
0120                 no_results = 1;
0121                 disp('No se puede ajustar el epsilon para este número de bits.');
0122                 break;
0123 
0124             elseif(iter == 1)
0125                 epsilon = epsilon_ini;
0126             end
0127         end
0128         if(no_results == 0)
0129 
0130             cd(directorio)
0131             unzip([fichero '_' num2str(i)]);
0132             if(algoritmo >= 4)
0133                 ristra = read_code_svr_nl([fichero '_' num2str(i) '.bin']);
0134                 Results(i).Exponente = exponente;
0135             else
0136                 ristra = read_code_svr_dct([fichero '_' num2str(i) '.bin']);
0137             end
0138 
0139             delete([fichero '_' num2str(i) '.bin']);
0140 
0141             D = dir([directorio fichero '_' num2str(i) '.zip']);
0142             tamanyo = 8 * D.bytes;
0143 
0144             entropia = tamanyo / N^2;
0145 
0146             Results(i).Bits = bits;
0147             Results(i).Epsilon = epsilon;
0148             Results(i).Kernel = K;
0149             Results(i).Entropy = entropia;
0150             Results(i).Image = ImR;
0151             Results(i).ristra = ristra;
0152             switch(variable)
0153                 case 'RMSE',
0154                     Results.RMSE = distorsion_actual;
0155                 case 'SSIM',
0156                     Results.SSIM = distorsion_actual;
0157                 case 'MPE lineal',
0158                     Results.MPE_lineal = distorsion_actual;
0159                 case 'MPE no lineal',
0160                     Results.MPE_no_lineal = distorsion_actual;
0161                 case 'MPE no lineal JMLR',
0162                     Results.MPE_no_lineal_JMLR = distorsion_actual;
0163             end
0164 
0165             ini_bits = b;
0166 
0167             break;
0168         end
0169     end
0170 end

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