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
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 function RESP=svr_nl_c_encoder_cs(Im,normaliz,To,dUmax,dVmax,bits,epsilonv,K,exponente,tipo_alfa,directorio,fichero,RESP)
0045
0046 you_are_here=pwd;
0047
0048 Im=double(Im);
0049
0050 if nargin<13
0051 RESP=[];
0052 end
0053
0054 MM = 0.8;
0055
0056 cero = 1;
0057
0058 Ncuan=4;
0059 tam=size(Im);
0060 if length(tam)==3
0061 capas=tam(3);
0062 else
0063 capas=1;
0064 end
0065
0066 tam=tam(1);
0067 lados=[tam tam];
0068 lcuan=tam/(2^Ncuan);
0069
0070 YUV=my_rgb2yuv(double(Im));
0071
0072 for i=1:capas
0073 dcti(:,:,i)=dct2r(YUV(:,:,i),Ncuan);
0074 end
0075
0076 [dct_contr,Lm]=contras3(dcti,Ncuan,normaliz,To,dUmax,dVmax);
0077
0078 W=1;
0079
0080 val_r=To;
0081
0082 e(:,:,1)=imdpcm(Lm(:,:,1),W,val_r(1));
0083 e(:,:,2)=imdpcm(Lm(:,:,2),W,val_r(2));
0084 e(:,:,3)=imdpcm(Lm(:,:,3),W,val_r(3));
0085
0086 N=round(0.9*[40 10 10]);
0087
0088 for i=1:3
0089 e1=e(:,:,i);
0090 me=mini(e1);
0091 Me=maxi(e1);
0092
0093 extr_err(:,i)=[me Me]';
0094
0095 QE(:,:,i)=round((N(i)-1)*(e1-me)/(Me-me));
0096
0097 end
0098
0099 masc=zeros(16,16);
0100 masc(1:8,1:8)=ones(8,8);
0101 masc=repmat(masc,16,16);
0102 dct_contr(:,:,2)=masc.*dct_contr(:,:,2);
0103 dct_contr(:,:,3)=masc.*dct_contr(:,:,3);
0104
0105 N=round(0.9*[40 10 10]);
0106 for i=1:3
0107 qe(:,:,i)=(extr_err(2,i)-extr_err(1,i))*QE(:,:,i)/(N(i)-1)+extr_err(1,i);
0108 LumQ(:,:,i)=iimdpcm(qe(:,:,i),1,val_r(i));
0109 end
0110
0111 R=(1:255);R=R(:);
0112
0113 C=40000;
0114 perfil_C=ones(255,1);
0115
0116 perfil_e=ones(255,1);
0117
0118 Lb = lcuan;
0119 Li = tam;
0120
0121 Results=[];
0122
0123 codigazoA=[];
0124 codigazoC1=[];
0125 codigazoC2=[];
0126
0127 codigazoA_eob=[];
0128 codigazoC1_eob=[];
0129 codigazoC2_eob=[];
0130
0131 [h,alpha,beta,gamm]=constrains_respY(exponente(1),cero,tipo_alfa);
0132 [hU,alphaU,betaU,gammU]=constrains_respU(exponente(2),cero);
0133 [hV,alphaV,betaV,gammV]=constrains_respV(exponente(3),cero);
0134
0135 epsilon=epsilonv;
0136
0137 betasc = zeros(256,255,3);
0138 betascr= zeros(256,255,3);
0139
0140 fprintf(' Training all the blocks of the local non-linear domain \n');
0141
0142 for cap=1:capas
0143 fprintf(' Channel %d: ',cap);
0144 bloquecito=1;
0145 for i=1:Lb:Li
0146 fprintf('.');
0147 for j=1:Lb:Li
0148
0149 aa=dct_contr(i:(i+(Lb-1)),j:(j+(Lb-1)),cap);
0150 azig = zigzag(aa);
0151 azigsc = azig(2:end);
0152
0153 signo = azigsc<0;
0154
0155 if nargin<13
0156 if cap==1
0157 [h_a,r,GR,alfa2d,beta2d]=respue5(aa,alpha,beta,gamm,h,0);
0158 elseif cap==2
0159 [h_a,r,GR,alfa2dU,beta2dU]=respue5(aa,alphaU,betaU,gammU,hU,0);
0160 else
0161 [h_a,r,GR,alfa2dV,beta2dV]=respue5(aa,alphaV,betaV,gammV,hV,0);
0162 end
0163 r=zigzag(r);
0164
0165 r = r(2:256).*(signo==0) - r(2:256).*(signo==1);
0166
0167 RESP(bloquecito,:,cap)=r';
0168
0169 else
0170
0171 r=RESP(bloquecito,:,cap)';
0172
0173 end
0174
0175 [nsv,pesosSVM,bias] = irwls_pd_svr_nobias(R,r,K,C,perfil_C,epsilon(cap),perfil_e);
0176 betasc(bloquecito,:,cap)=pesosSVM';
0177 bloquecito=bloquecito+1;
0178 end
0179 end
0180 fprintf('\n');
0181 end
0182 fprintf('\n');
0183
0184 for cap=1:capas
0185
0186 NumNiv(cap) = 2^bits(cap);
0187
0188 betascr(:,:,cap) = round( NumNiv(cap) * betasc(:,:,cap)/MM)*MM/NumNiv(cap);
0189
0190 rc=[];
0191 for fila=1:Li
0192 rc= [rc; (K*betascr(fila,:,cap)')'];
0193 end
0194
0195 if cap==1
0196
0197 codigonA(:,:,cap) = betascr(:,:,cap);
0198 codigonAint(:,:,cap)=codigonA*NumNiv(cap)/MM;
0199
0200 for i=1:Lb^2
0201 [cod,ceros]=rle2(codigonAint(i,:,cap));
0202
0203 codigazoA_eob=[codigazoA_eob cod ceros 1e8];
0204 codigazoA=[codigazoA cod ceros];
0205 end
0206
0207 else
0208
0209 codigonCcompleto(:,:,cap-1)=betascr(:,:,cap);
0210 codigonCintcompleto(:,:,cap-1)=codigonCcompleto(:,:,cap-1)*NumNiv(cap)/MM;
0211
0212 for i=1:Lb^2
0213
0214 bet = betascr(i,:,cap);
0215 bet=dezigzag([0 bet]);
0216 bet=bet(1:8,1:8);
0217 bet=zigzag(bet);
0218 codigonC(i,:,cap-1)=bet(2:end);
0219 codigonCint(i,:,cap-1)=codigonC(i,:,cap-1)*NumNiv(cap)/MM;
0220
0221 [cod,ceros]=rle2(codigonCint(i,:,cap-1));
0222
0223 if cap==2
0224 codigazoC1_eob=[codigazoC1_eob cod ceros 1e8];
0225 codigazoC1=[codigazoC1 cod ceros];
0226 else
0227 codigazoC2_eob=[codigazoC2_eob cod ceros 1e8];
0228 codigazoC2=[codigazoC2 cod ceros];
0229 end
0230 end
0231 end
0232
0233 end
0234
0235 repBloquesY=dct_ac_rows_to_patches(codigonAint);
0236 repBloquesU=dct_ac_rows_to_patches(codigonCintcompleto(:,:,1));
0237 repBloquesV=dct_ac_rows_to_patches(codigonCintcompleto(:,:,2));
0238
0239 ristra = [extr_err(:)' round(QE(:))' bits round(codigazoA) round(codigazoC1) round(codigazoC2)];
0240
0241 cd(directorio);
0242 save_code(ristra,[fichero '.bin']);
0243
0244 zip(fichero,[fichero '.bin']);
0245
0246 delete([fichero '.bin']);
0247
0248 cd(you_are_here)