distortion_nl_svr

PURPOSE ^

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

SYNOPSIS ^

function [Results_NL_SVR] = distortion_nl_svr(Im,normaliz,To,dUmax,dVmax,epsilonv,K,exponente,tipo_alfa,variable,parametro,directorio,fichero)

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 code 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 code 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 
0013 function [Results_NL_SVR] = distortion_nl_svr(Im,normaliz,To,dUmax,dVmax,epsilonv,K,exponente,tipo_alfa,variable,parametro,directorio,fichero)
0014 Results_NL_SVR = [];
0015 
0016 pesoY = 0.7;
0017 pesoU = 0.15;
0018 pesoV = 0.15;
0019 
0020 ini_bits = 2;
0021 fin_bits = 15;
0022 for i = 1:length(parametro)
0023 
0024     ImR_nl_svr = [];
0025     disp(['Ajustando el epsilon para hallar el ' variable ' de:   ' num2str(parametro(i))]);
0026     for b = ini_bits:0.5:fin_bits
0027         switch(variable)
0028             case 'RMSE', parametro_actual = 0; umbral = 0.01;
0029             case 'SSIM', parametro_actual = 0; umbral = 0.001;
0030             case 'MPE lineal', parametro_actual = 100; umbral = 0.01;
0031             case 'MPE no lineal', parametro_actual = 100; umbral = 0.01;
0032             case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.1;
0033             case 'SCIELab', parametro_actual = 0; umbral = 0.01;
0034         end
0035 
0036         epsilon = [0 0 0];
0037 
0038         bits = b .* [1 1 1];
0039 
0040         iter = 0;
0041 
0042         porcentaje = 1;
0043 
0044         if(isequal(variable,'SSIM'))
0045             sentido = 0;
0046         else
0047             sentido = 1;
0048         end
0049 
0050         l_min = 0;
0051         l_max = 100000;
0052 
0053         no_results = 0;
0054         while((abs(parametro(i) - parametro_actual) > umbral) & (iter < 30))
0055             iter = iter + 1;
0056 
0057             if(iter ~= 1 && iter ~= 2)
0058                 if(isequal(variable,'SSIM'))
0059                     [epsilon2, l_min, l_max, porcentaje, sentido] = fitting_epsilon_SSIM(parametro(i), parametro_actual, epsilon(1), l_min, l_max, porcentaje, sentido);
0060                 else
0061                     [epsilon2, l_min, l_max, porcentaje, sentido] = fitting_epsilon(parametro(i), parametro_actual, epsilon(1), l_min, l_max, porcentaje, sentido);
0062                 end
0063                 epsilon = epsilon2 .* [1 1 1];
0064             end
0065 
0066             [encoder_nl_svr] = svr_nl_c_encoder_cs(Im,normaliz,To,dUmax,dVmax,bits,epsilon,K,exponente,tipo_alfa,directorio,[fichero '_' num2str(i)]);
0067             close all
0068 
0069             [ImR_nl_svr] = svr_nl_c_decoder_cs(normaliz,To,dUmax,dVmax,K,exponente,tipo_alfa,directorio,[fichero '_' num2str(i)]);
0070 
0071             mse = zeros(3,1);
0072             esesim = zeros(3,1);
0073             MPEl = zeros(3,1);
0074             MPEnl = zeros(3,1);
0075             MPEnlJMLR = zeros(3,1);
0076             SCIELab = 0;
0077 
0078             Im_yuv = my_rgb2yuv(double(Im));
0079             ImR_NL_SVR_yuv = my_rgb2yuv(ImR_nl_svr);
0080 
0081             for capa = 1:3
0082                 switch(variable)
0083                     case 'RMSE',
0084                         [mse(capa),SNRi] = emse2(double(Im_yuv(:,:,capa)),ImR_NL_SVR_yuv(:,:,capa));
0085                     case 'SSIM',
0086                         esesim(capa) = ssim_index(double(Im_yuv(:,:,capa)),ImR_NL_SVR_yuv(:,:,capa));
0087                     case 'MPE lineal',
0088                         [MSE,MPEl(capa),dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(double(Im_yuv(:,:,capa)),ImR_NL_SVR_yuv(:,:,capa),2,[3 mean(mean(Im_yuv(:,:,capa)))],2,2);
0089                     case 'MPE no lineal',
0090                         [MSE,MPEnl(capa),dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im_yuv(:,:,capa)),ImR_NL_SVR_yuv(:,:,capa),[3 mean(mean(Im_yuv(:,:,capa)))],2,1,2,2);
0091                     case 'MPE no lineal JMLR',
0092                         [MSE,MPEnlJMLR(capa),dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im_yuv(:,:,capa)),ImR_NL_SVR_yuv(:,:,capa),[3 mean(mean(Im_yuv(:,:,capa)))],1,0.5,2,2);
0093                 end
0094             end
0095             if(isequal(variable,'SCIELab'))
0096                 SCIELab = calculo_scielab(Im,ImR_nl_svr);
0097             end
0098             switch(variable)
0099                 case 'RMSE',
0100                     mse = pesoY * mse(1) + pesoU * mse(2) + pesoV * mse(3);
0101                     parametro_actual = sqrt(mse);
0102                 case 'SSIM',
0103                     esesim = pesoY * esesim(1) + pesoU * esesim(2) + pesoV * esesim(3);
0104                     parametro_actual = esesim;
0105                 case 'MPE lineal',
0106                     parametro_actual = pesoY * MPEl(1) + pesoU * MPEl(2) + pesoV * MPEl(3);
0107                 case 'MPE no lineal',
0108                     parametro_actual = pesoY * MPEnl(1) + pesoU * MPEnl(2) + pesoV * MPEnl(3);
0109                 case 'MPE no lineal JMLR',
0110                     parametro_actual = pesoY * MPEnlJMLR(1) + pesoU * MPEnlJMLR(2) + pesoV * MPEnlJMLR(3);
0111                 case 'SCIELab'
0112                     parametro_actual = SCIELab;
0113             end
0114             disp(['Iteracion:  ' num2str(iter) '   ' variable ':  ' num2str(parametro_actual) '   bits:  ' num2str(bits(1)) '   epsilon:  ' num2str(epsilon(1))]);
0115 
0116             if(~isequal(variable,'SSIM') && (iter == 1) && (parametro(i) - parametro_actual < 0) && (epsilon(1) == 0))
0117                 no_results = 1;
0118                 disp('No se puede ajustar el epsilon para este número de bits.');
0119                 break;
0120 
0121             elseif(isequal(variable,'SSIM') && (iter == 1) && (parametro(i) - parametro_actual > 0) && (epsilon(1) == 0))
0122                 no_results = 1;
0123                 disp('No se puede ajustar el epsilon para este número de bits.');
0124                 break;
0125 
0126             elseif((iter == 1) && (abs(parametro(i) - parametro_actual) <= umbral) && (epsilon(1) == 0))
0127 
0128                 epsilon = epsilonv;
0129 
0130                 parametro_actual = 0;
0131 
0132             elseif(iter == 1)
0133                 epsilon = epsilonv;
0134             end
0135         end
0136         if(no_results == 0)
0137 
0138             cd(directorio)
0139             unzip([fichero '_' num2str(i)]);
0140             ristra = read_code([fichero '_' num2str(i) '.bin']);
0141 
0142             delete([fichero '_' num2str(i) '.bin']);
0143 
0144             D = dir([directorio fichero '_' num2str(i) '.zip']);
0145             tamanyo = 8 * D.bytes;
0146 
0147             entropia = tamanyo / size(ImR_nl_svr,1)^2;
0148 
0149             Results_NL_SVR(i).Normalizacion = normaliz;
0150             Results_NL_SVR(i).To = To;
0151             Results_NL_SVR(i).dUmax = dUmax;
0152             Results_NL_SVR(i).dVmax = dVmax;
0153             Results_NL_SVR(i).Bits = bits;
0154             Results_NL_SVR(i).Epsilon = epsilon;
0155             Results_NL_SVR(i).Kernel = K;
0156             Results_NL_SVR(i).Exponente = exponente;
0157             Results_NL_SVR(i).Tipo_alfa = tipo_alfa;
0158             Results_NL_SVR(i).Entropy = entropia;
0159             Results_NL_SVR(i).Image = ImR_nl_svr;
0160             Results_NL_SVR(i).ristra = ristra;
0161             switch(variable)
0162                 case 'RMSE',
0163                     Results_NL_SVR(i).RMSE = parametro_actual;
0164                 case 'SSIM',
0165                     Results_NL_SVR(i).SSIM = parametro_actual;
0166                 case 'MPE lineal',
0167                     Results_NL_SVR(i).MPE_lineal = parametro_actual;
0168                 case 'MPE no lineal',
0169                     Results_NL_SVR(i).MPE_no_lineal = parametro_actual;
0170                 case 'MPE no lineal JMLR',
0171                     Results_NL_SVR(i).MPE_no_lineal_JMLR = parametro_actual;
0172                 case 'SCIELab'
0173                     Results_NL_SVR(i).SCIELab = SCIELab;
0174             end
0175 
0176             ini_bits = b;
0177 
0178             break;
0179         end
0180     end
0181 end

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