0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 function [Results_JPEG] = distortion_jpeg(Im,normaliz,To,dUmax,dVmax,uCPv,variable,parametro,directorio,fichero,niveles,bitmax)
0012 Results_JPEG = [];
0013
0014 if(nargin < 12 && niveles == 1)
0015 bitmax = 1;
0016 end
0017
0018 pesoY = 0.7;
0019 pesoU = 0.15;
0020 pesoV = 0.15;
0021 for i = 1:length(parametro)
0022
0023 uCP = [0 0 0];
0024
0025 iter = 0;
0026
0027 porcentaje = 1;
0028
0029 if(isequal(variable,'SSIM'))
0030 sentido = 1;
0031 else
0032 sentido = 0;
0033 end
0034
0035 l_min = 0;
0036 l_max = 100000;
0037
0038 switch(variable)
0039 case 'RMSE', parametro_actual = 0; umbral = 0.01;
0040 case 'SSIM', parametro_actual = 0; umbral = 0.001;
0041 case 'MPE lineal', parametro_actual = 100; umbral = 0.01;
0042 case 'MPE no lineal', parametro_actual = 100; umbral = 0.01;
0043 case 'MPE no lineal JMLR', parametro_actual = 100; umbral = 0.1;
0044 case 'SCIELab', parametro_actual = 0; umbral = 0.01;
0045 end
0046
0047 no_results = 0;
0048 disp(['Ajustando el uCP para hallar un ' variable ' de: ' num2str(parametro(i))]);
0049 while((abs(parametro(i) - parametro_actual) > umbral) && (iter < 30))
0050 iter = iter + 1;
0051
0052 if(iter ~= 1 && iter ~= 2)
0053 if(isequal(variable,'SSIM'))
0054 [uCP2, l_min, l_max, porcentaje, sentido] = fitting_uCP_SSIM(parametro(i), parametro_actual, uCP(1), l_min, l_max, porcentaje, sentido);
0055 else
0056 [uCP2, l_min, l_max, porcentaje, sentido] = fitting_uCP(parametro(i), parametro_actual, uCP(1), l_min, l_max, porcentaje, sentido);
0057 end
0058
0059 uCP = uCP2 .* [1 1 1];
0060 end
0061
0062 jpeg91_c_encoder(Im,normaliz,To,dUmax,dVmax,uCP,0,directorio,[fichero '_' num2str(i)],niveles,bitmax);
0063
0064 ImR_jpeg = jpeg91_c_decoder(normaliz,To,dUmax,dVmax,directorio,[fichero '_' num2str(i)],niveles,bitmax);
0065
0066 mse = zeros(3,1);
0067 esesim = zeros(3,1);
0068 MPEl = zeros(3,1);
0069 MPEnl = zeros(3,1);
0070 MPEnlJMLR = zeros(3,1);
0071 SCIELab = 0;
0072
0073 Im_yuv = my_rgb2yuv(double(Im));
0074 ImR_JPEG_yuv = my_rgb2yuv(ImR_jpeg);
0075
0076 for capa = 1:3
0077 switch(variable)
0078 case 'RMSE',
0079 [mse(capa),SNRi] = emse2(double(Im_yuv(:,:,capa)),ImR_JPEG_yuv(:,:,capa));
0080 case 'SSIM',
0081 esesim(capa) = ssim_index(double(Im_yuv(:,:,capa)),ImR_JPEG_yuv(:,:,capa));
0082 case 'MPE lineal',
0083 [MSE,MPEl(capa),dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(double(Im_yuv(:,:,capa)),ImR_JPEG_yuv(:,:,capa),2,[3 mean(mean(Im_yuv(:,:,capa)))],2,2);
0084 case 'MPE no lineal',
0085 [MSE,MPEnl(capa),dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im_yuv(:,:,capa)),ImR_JPEG_yuv(:,:,capa),[3 mean(mean(Im_yuv(:,:,capa)))],2,1,2,2);
0086 case 'MPE no lineal JMLR',
0087 [MSE,MPEnlJMLR(capa),dx,MPEx,MPEoo,MPEexpesp] = disdis7(double(Im_yuv(:,:,capa)),ImR_JPEG_yuv(:,:,capa),[3 mean(mean(Im_yuv(:,:,capa)))],1,0.5,2,2);
0088 end
0089 end
0090 if(isequal(variable,'SCIELab'))
0091 SCIELab = calculo_scielab(Im,ImR_jpeg);
0092 end
0093 switch(variable)
0094 case 'RMSE',
0095 mse = pesoY * mse(1) + pesoU * mse(2) + pesoV * mse(3);
0096 parametro_actual = sqrt(mse);
0097 case 'SSIM',
0098 esesim = pesoY * esesim(1) + pesoU * esesim(2) + pesoV * esesim(3);
0099 parametro_actual = esesim;
0100 case 'MPE lineal',
0101 parametro_actual = pesoY * MPEl(1) + pesoU * MPEl(2) + pesoV * MPEl(3);
0102 case 'MPE no lineal',
0103 parametro_actual = pesoY * MPEnl(1) + pesoU * MPEnl(2) + pesoV * MPEnl(3);
0104 case 'MPE no lineal JMLR',
0105 parametro_actual = pesoY * MPEnlJMLR(1) + pesoU * MPEnlJMLR(2) + pesoV * MPEnlJMLR(3);
0106 case 'SCIELab'
0107 parametro_actual = SCIELab;
0108 end
0109 disp(['Iteracion: ' num2str(iter) ' ' variable ': ' num2str(parametro_actual) ' uCP: ' num2str(uCP(1))]);
0110
0111 if(~isequal(variable,'SSIM') && (iter == 1) && (parametro(i) - parametro_actual > 0) && (uCP(1) == 0))
0112 no_results = 1;
0113 disp('No se puede ajustar el uCP.');
0114 break;
0115
0116 elseif(isequal(variable,'SSIM') && (iter == 1) && (parametro(i) - parametro_actual < 0) && (uCP(1) == 0))
0117 no_results = 1;
0118 disp('No se puede ajustar el uCP.');
0119 break;
0120
0121 elseif((iter == 1) && (abs(parametro(i) - parametro_actual) <= umbral) && (uCP(1) == 0))
0122
0123 uCP = uCPv;
0124
0125 parametro_actual = 0;
0126
0127 elseif(iter == 1)
0128 uCP = uCPv;
0129 end
0130 end
0131 if(no_results == 0)
0132
0133 cd(directorio)
0134 unzip([fichero '_' num2str(i)]);
0135 ristra = read_code([fichero '_' num2str(i) '.bin']);
0136
0137 delete([fichero '_' num2str(i) '.bin']);
0138
0139 D = dir([directorio fichero '_' num2str(i) '.zip']);
0140 tamanyo = 8 * D.bytes;
0141
0142 entropia = tamanyo / prod([size(ImR_jpeg,1) size(ImR_jpeg,2)]);
0143
0144 Results_JPEG(i).Normalizacion = normaliz;
0145 Results_JPEG(i).To = To;
0146 Results_JPEG(i).dUmax = dUmax;
0147 Results_JPEG(i).dVmax = dVmax;
0148 Results_JPEG(i).Niveles = niveles;
0149 Results_JPEG(i).Entropy = entropia;
0150 Results_JPEG(i).uCP = uCP;
0151 Results_JPEG(i).Image = ImR_jpeg;
0152 Results_JPEG(i).ristra = ristra;
0153 switch(variable)
0154 case 'RMSE',
0155 Results_JPEG(i).RMSE = parametro_actual;
0156 case 'SSIM',
0157 Results_JPEG(i).SSIM = parametro_actual;
0158 case 'MPE lineal',
0159 Results_JPEG(i).MPE_lineal = parametro_actual;
0160 case 'MPE no lineal',
0161 Results_JPEG(i).MPE_no_lineal = parametro_actual;
0162 case 'MPE no lineal JMLR',
0163 Results_JPEG(i).MPE_no_lineal_JMLR = parametro_actual;
0164 case 'SCIELab'
0165 Resutls_JPEG(i).SCIELab = parametro_actual;
0166 end
0167 end
0168 end