0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 function [Results] = svr_dct_epsilon_bits_entropy(Im,epsilon_inicial,H,perfil,sepsigno)
0029
0030 Lb=16;
0031 Li=length(Im);
0032
0033 R=1:(Lb*Lb-1); R=R(:);
0034 N=length(R);
0035
0036 C=40000;
0037 D = ones(1,N); D = D(:);
0038
0039 res = 0;
0040
0041 Results=[];
0042
0043 ent_inicial = 0.05;
0044
0045 ent_final = 0.8;
0046
0047 ini_bits = 2;
0048
0049 fin_bits = 8;
0050
0051 for entropiad = ent_inicial:0.05:ent_final
0052
0053 for bits = ini_bits:0.5:fin_bits
0054
0055 ImR = rand(Li);
0056
0057 entropiat = 10;
0058 umbral = 0.005;
0059
0060 epsilon = 0;
0061
0062 iter = 0;
0063
0064 porcentaje = 1;
0065
0066 sentido = 0;
0067
0068 no_results = 0;
0069
0070 l_min = 0;
0071 l_max = 100000;
0072
0073 while (abs(entropiad - entropiat) > umbral) & (iter < 30)
0074
0075 iter = iter + 1;
0076
0077 signoscoefs=[];
0078 betasc=[];
0079 BtC=[];
0080 Coef11=[];
0081 SVs=[];
0082 lSVs=[];
0083
0084 if(iter ~= 1 & iter ~= 2)
0085
0086 [epsilon, l_min, l_max, porcentaje, sentido] = fitting_epsilon_entropy(entropiad, entropiat, epsilon, l_min, l_max, porcentaje, sentido);
0087 end
0088
0089 fprintf('Training all the blocks of the local DCT');
0090
0091 for i=1:Lb:Li
0092
0093 fprintf('.');
0094
0095 for j=1:Lb:Li
0096
0097 B=Im(i:(i+(Lb-1)),j:(j+(Lb-1)));
0098 B=dct2(B);
0099 Coef11=[Coef11;B(1,1)];
0100 B=zigzag(B);
0101 B=B(2:end);
0102 BtC=[BtC;B'];
0103
0104 bitsig=getsign(B,Lb);
0105 signoscoefs = [signoscoefs; bitsig];
0106
0107 [nsv,beta,bias] = irwls_pd_svr_nobias(R,abs(B),H,C,D,epsilon,perfil);
0108
0109 betasc=[betasc;beta'];
0110
0111 end
0112 end
0113
0114 fprintf('\n');
0115
0116 MM=max(max(abs(betasc))); MM=MM/4;
0117
0118 NumNiv = 2^bits;
0119
0120 betascr = round( NumNiv * betasc/MM)*MM/NumNiv;
0121
0122 signos = zeros(size(signoscoefs));
0123 signos(logical(betascr~=0))=signoscoefs(logical(betascr~=0));
0124
0125 entropc = [];
0126 entrops = [];
0127
0128 codigon = betascr.*(~signos) - betascr.*(signos);
0129 for i=1:Lb^2
0130
0131 if sepsigno==0
0132 codigo = betascr(i,:).*(~signos(i,:)) - betascr(i,:).*(signos(i,:));
0133 [rlePesos,repCeros] = rle2(codigo);
0134 entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0135 entrops = 0;
0136 else
0137
0138 [rlePesos,repCeros] = rle2(betascr(i,:));
0139 entropc = [entropc length(rlePesos)*entropiv(rlePesos)+length(repCeros)*entropiv(repCeros)];
0140
0141 [rlePesoss,repCeross] = rle2(signos(i,:));
0142 entrops = [entrops length(rlePesoss)*entropiv(rlePesoss)+length(repCeross)*entropiv(repCeross)];
0143 end;
0144
0145 end
0146
0147 entropcn = sum(entropc)/Li^2;
0148 entropsn = sum(entrops)/Li^2;
0149
0150 entropiat = entropcn + entropsn;
0151
0152 fprintf(' It. =
0153
0154 if((iter == 1) & (entropiad - entropiat > 0) & (epsilon == 0))
0155 no_results = 1;
0156 disp('No se puede ajustar el epsilon para este nĂºmero de bits');
0157 break;
0158
0159 elseif((iter == 1) & (abs(entropiad - entropiat) <= umbral) & (epsilon == 0))
0160
0161 epsilon = epsilon_inicial;
0162
0163 entropiat = 10;
0164
0165 elseif(iter == 1)
0166 epsilon = epsilon_inicial;
0167 end
0168 end
0169
0170 if(no_results == 0)
0171
0172 z=1;
0173
0174 for i=1:Lb:Li
0175 for j=1:Lb:Li
0176
0177 y=H*betascr(z,:)';
0178
0179 y=obtainsign(y, signos, Lb,z);
0180
0181 A=dezigzag([Coef11(z);y]);
0182
0183 A=idct2(A);
0184
0185 ImR(i:(i+(Lb-1)),j:(j+(Lb-1)))=A;
0186
0187 z=z+1;
0188
0189 end
0190 end
0191
0192 [mse,SNRi] = emse2(Im,ImR);
0193
0194 esesim = ssim_index(Im,ImR);
0195
0196 [MSE,d_l,dx0,MPEx0,MPEoo0,MPEexpesp0] = disdis_lineal(Im,ImR,2,[3 mean(mean(Im))],2,2);
0197 mpelin = d_l;
0198
0199 [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],1,0.5,2,2);
0200 mpenonlinJMLR= d;
0201
0202 [MSE,d,dx,MPEx,MPEoo,MPEexpesp] = disdis7(Im,ImR,[3 mean(mean(Im))],2,1,2,2);
0203 mpenonlin= d;
0204
0205 res = res + 1;
0206
0207 Results(res).bits = bits;
0208 Results(res).epsilon = epsilon;
0209 Results(res).C = C;
0210 Results(res).entropia = entropiat;
0211 Results(res).Image = ImR;
0212 Results(res).MSE = mse;
0213 Results(res).SSIM = esesim;
0214 Results(res).MPE_lin = mpelin;
0215 Results(res).MPE_no_lin = mpenonlin;
0216 Results(res).MPE_no_lin_JMLR = mpenonlinJMLR;
0217
0218 end
0219 end
0220 end