distortion_ucp

PURPOSE ^

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

SYNOPSIS ^

function [Results] = distortion_ucp(algoritmo,variable,distorsiones,Im,uCP_ini,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  "sequence" and decodes the image using
 the JPEG91, Malo99, Epifanio03, Malo06 algorithm.
 It computes the distortion and reset the uCP 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  "sequence" and decodes the image using
0005 % the JPEG91, Malo99, Epifanio03, Malo06 algorithm.
0006 % It computes the distortion and reset the uCP 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] = distortion_ucp(algoritmo,variable,distorsiones,Im,uCP_ini,exponente,directorio)
0014 N = length(Im);
0015 for i = 1:length(distorsiones)
0016 
0017     ImR = [];
0018     disp(['Ajustando el epsilon para hallar el ' variable ' de:   ' num2str(distorsiones(i))]);
0019     switch(variable)
0020         case 'RMSE', distorsion_actual = 0; umbral = 0.01;
0021         case 'SSIM', distorsion_actual = 0; umbral = 0.001;
0022         case 'MPE lineal', distorsion_actual = 100; umbral = 0.01;
0023         case 'MPE no lineal', distorsion_actual = 100; umbral = 0.01;
0024         case 'MPE no lineal JMLR', distorsion_actual = 100; umbral = 0.1;
0025     end
0026 
0027     uCP = 0;
0028 
0029     iter = 0;
0030 
0031     porcentaje = 1;
0032 
0033     if(isequal(variable,'SSIM'))
0034         sentido = 0;
0035     else
0036         sentido = 1;
0037     end
0038 
0039     l_min = 0;
0040     l_max = 100000;
0041 
0042     no_results = 0;
0043     while((abs(distorsiones(i) - distorsion_actual) > umbral) & (iter < 30))
0044         iter = iter + 1;
0045 
0046         if(iter ~= 1 & iter ~= 2)
0047             if(isequal(variable,'SSIM'))
0048                 [uCP,l_min,l_max,porcentaje,sentido] = fitting_uCP_SSIM(distorsiones(i),distorsion_actual,uCP,l_min,l_max,porcentaje,sentido);
0049             else
0050                 [uCP,l_min,l_max,porcentaje,sentido] = fitting_uCP(distorsiones(i),distorsion_actual,uCP,l_min,l_max,porcentaje,sentido);
0051             end
0052         end
0053 
0054         switch(algoritmo)
0055             case 6,
0056                 fichero = 'jpeg91_distorsion';
0057                 jpeg91_encoder(Im,uCP,directorio,[fichero '_' num2str(i)]);
0058             case 7,
0059                 fichero = 'malo99_entropia';
0060                 malo99_encoder(Im,uCP,directorio,[fichero '_' num2str(i)]);
0061             case 8,
0062             case 9,
0063                 fichero = 'malo06_1_distorsion';
0064                 malo06_encoder(Im,uCP,exponente,directorio,[fichero '_' num2str(i)]);
0065             case 10,
0066                 fichero = 'malo06_2_distorsion';
0067                 malo06_encoder(Im,uCP,exponente,directorio,[fichero '_' num2str(i)]);
0068         end
0069 
0070         switch(algoritmo)
0071             case 6,
0072                 [ImR] = jpeg91_decoder(directorio,[fichero '_' num2str(i)]);
0073             case 7,
0074                 [ImR] = malo99_decoder(directorio,[fichero '_' num2str(i)]);
0075             case 8,
0076             case 9,
0077                 [ImR] = malo06_decoder(exponente,directorio,[fichero '_' num2str(i)]);
0078             case 10,
0079                 [ImR] = malo06_decoder(exponente,directorio,[fichero '_' num2str(i)]);
0080         end
0081 
0082         switch(variable)
0083             case 'RMSE',
0084                 [mse,SNRi] = emse2(double(Im),ImR);
0085                 distorsion_actual = sqrt(mse);
0086             case 'SSIM',
0087                 esesim = ssim_index(double(Im),ImR);
0088                 distorsion_actual = esesim;
0089             case 'MPE lineal',
0090                 [MSE,MPEl,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(double(Im),ImR,2,[3 mean(mean(Im))],2,2);
0091                 distorsion_actual = MPEl;
0092             case 'MPE no lineal',
0093                 [MSE,MPEnl,dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im),ImR,[3 mean(mean(Im))],2,1,2,2);
0094                 distorsion_actual = MPEnl;
0095             case 'MPE no lineal JMLR',
0096                 [MSE,MPEnlJMLR,dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im),ImR,[3 mean(mean(Im))],1,0.5,2,2);
0097                 distorsion_actual = MPEnlJMLR;
0098         end
0099         disp(['Iteracion:  ' num2str(iter) '   ' variable ':  ' num2str(distorsion_actual) '   bits:  ' num2str(bits) '   epsilon:  ' num2str(epsilon)]);
0100 
0101         if(~isequal(variable,'SSIM') & (iter == 1) & (distorsiones(i) - distorsion_actual > 0) & (uCP == 0))
0102             no_results = 1;
0103             disp('No se puede ajustar el uCP.');
0104             break;
0105 
0106         elseif(isequal(variable,'SSIM') & (iter == 1) & (distorsiones(i) - distorsion_actual < 0) & (uCP == 0))
0107             no_results = 1;
0108             disp('No se puede ajustar el uCP.');
0109             break;
0110 
0111         elseif((iter == 1) & (abs(distorsiones(i) - distorsion_actual) <= umbral) & (uCP == 0))
0112             no_results = 1;
0113             disp('No se puede ajustar el uCP.');
0114             break;
0115 
0116         elseif(iter == 1)
0117             uCP = uCP_ini;
0118         end
0119     end
0120     if(no_results == 0)
0121 
0122         cd(directorio)
0123         unzip([fichero '_' num2str(i)]);
0124         if(algoritmo >= 9)
0125             ristra = read_code_malo06([fichero '_' num2str(i) '.bin']);
0126             Results(i).Exponente = exponente;
0127         elseif(algoritmo == 6)
0128             ristra = read_code_jpeg91([fichero '_' num2str(i) '.bin']);
0129         elseif(algoritmo == 7)
0130             ristra = read_code_malo99([fichero '_' num2str(i) '.bin']);
0131 
0132         end
0133 
0134         delete([fichero '_' num2str(i) '.bin']);
0135 
0136         D = dir([directorio fichero '_' num2str(i) '.zip']);
0137         tamanyo = 8 * D.bytes;
0138 
0139         entropia = tamanyo / N^2;
0140 
0141         Results(i).uCP = uCP;
0142         Results(i).Entropy = entropia;
0143         Results(i).Image = ImR;
0144         Results(i).ristra = ristra;
0145         switch(variable)
0146             case 'RMSE',
0147                 Results(i).RMSE = distorsion_actual;
0148             case 'SSIM',
0149                 Results(i).SSIM = distorsion_actual;
0150             case 'MPE lineal',
0151                 Results(i).MPE_lineal = distorsion_actual;
0152             case 'MPE no lineal',
0153                 Results(i).MPE_no_lineal = distorsion_actual;
0154             case 'MPE no lineal JMLR',
0155                 Results(i).MPE_no_lineal_JMLR = distorsion_actual;
0156         end
0157     end
0158 end

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