svr_nl_c_encoder_cs

PURPOSE ^

SVR_NL_C_ENCODER encoding images by quantization of the SVM weights trained in the DCT domain

SYNOPSIS ^

function RESP=svr_nl_c_encoder_cs(Im,normaliz,To,dUmax,dVmax,bits,epsilonv,K,exponente,tipo_alfa,directorio,fichero,RESP)

DESCRIPTION ^

 SVR_NL_C_ENCODER encoding images by quantization of the SVM weights trained in the DCT domain
 of the chromatic YUV channels transformed by divisive normalization (currently 256 * 256 images)

 The DC components are coded by DPCM in YUV.

 Before applying non - linear responses DCTs must be expressed in
 contrasts (chromatic and achromatic) by using contras3.m
 This function allows three modes of normalization:

 Norm = 1 ................ Calculates contrast in each block by reference to the average color of
 the whole picture.

 Norm = 2 ................ Calculates contrast in each block by reference to the average color of
 that block.

 Norm = 3 ................ Calculates contrast in each block with reference to color ( RGB NTSC)
 that is passed. ( in the other cases put To = 0)

 To calculate the chromatic contrasts we have to define what we
 call Contrast unit (set the maximum variation of the U -channel and
 V , and Dumax dVmax). It is reasonable to set these parameters around 50.

 Uniform quantization SVMs weights of each block of each channel is determined
 by a number of bits for each channel. The number of support vectors
 depends on the epsilon-insensitivity that is set for the Machine.

 K_svm is the kernel used in the machines. This is a rbf kernel
 K = kernel2d_variance(16,1);

 The parameter 'exponent' contains the exponents of excitement and
 inhibition for each channel. There are two options:

 Exp = 2 ... better results but more unstable inverse.
 Exp = 1 ... worse but more robust inverse.

 You can choose different CSFs for the achromatic channel:
 Tipo_alfa = 1 Selects adjusted CSF
 Tipo_alfa = 2 Selects Ngan CSF
 Tipo_alfa = 3 Selects Kelly CSF (as earlier versions of JPEG)

 USE: [Results]=svr_nl_c_encoder(Im,norm,To,dUmax,dVmax,bits,epsilonv,K_svm,exponente,tipo_alfa,directorio,fichero,RESP))

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % SVR_NL_C_ENCODER encoding images by quantization of the SVM weights trained in the DCT domain
0002 % of the chromatic YUV channels transformed by divisive normalization (currently 256 * 256 images)
0003 %
0004 % The DC components are coded by DPCM in YUV.
0005 %
0006 % Before applying non - linear responses DCTs must be expressed in
0007 % contrasts (chromatic and achromatic) by using contras3.m
0008 % This function allows three modes of normalization:
0009 %
0010 % Norm = 1 ................ Calculates contrast in each block by reference to the average color of
0011 % the whole picture.
0012 %
0013 % Norm = 2 ................ Calculates contrast in each block by reference to the average color of
0014 % that block.
0015 %
0016 % Norm = 3 ................ Calculates contrast in each block with reference to color ( RGB NTSC)
0017 % that is passed. ( in the other cases put To = 0)
0018 %
0019 % To calculate the chromatic contrasts we have to define what we
0020 % call Contrast unit (set the maximum variation of the U -channel and
0021 % V , and Dumax dVmax). It is reasonable to set these parameters around 50.
0022 %
0023 % Uniform quantization SVMs weights of each block of each channel is determined
0024 % by a number of bits for each channel. The number of support vectors
0025 % depends on the epsilon-insensitivity that is set for the Machine.
0026 %
0027 % K_svm is the kernel used in the machines. This is a rbf kernel
0028 % K = kernel2d_variance(16,1);
0029 %
0030 % The parameter 'exponent' contains the exponents of excitement and
0031 % inhibition for each channel. There are two options:
0032 %
0033 % Exp = 2 ... better results but more unstable inverse.
0034 % Exp = 1 ... worse but more robust inverse.
0035 %
0036 % You can choose different CSFs for the achromatic channel:
0037 % Tipo_alfa = 1 Selects adjusted CSF
0038 % Tipo_alfa = 2 Selects Ngan CSF
0039 % Tipo_alfa = 3 Selects Kelly CSF (as earlier versions of JPEG)
0040 %
0041 % USE: [Results]=svr_nl_c_encoder(Im,norm,To,dUmax,dVmax,bits,epsilonv,K_svm,exponente,tipo_alfa,directorio,fichero,RESP))
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)

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