jpeg91_encoder

PURPOSE ^

It employs QDCT55 to quantize the DCTs patches with resolution N from a 2D signal

SYNOPSIS ^

function jpeg91_encoder(s,B,directorio,fichero)

DESCRIPTION ^

 It employs QDCT55 to quantize the DCTs patches with resolution N from a 2D signal

 QDCT55 allows designing the VQ using the IAF or the statistics, or to introduce some other quantizer
 previously design (contains APELES Y VQPERC, y QDCT21)

 Introduce 1 in the 'opc' variable to compute the PERCEPTUAL VQ.
 Then you need to give the the needed parameters to the function (See VQPERC.m).
  * Quantization using a perceptual VQ needs:
         señal,Ncuan,opc = 1,facfrec,ncontr,nolin,estab,
           B,bitmax,fc,cc,crit,fijarmax,inclcsf,frecbaja.

 Introduce 2 in the 'opc' variable to compute the ESTATISTICAL VQ.
 Then you need to give the the needed parameters to the function (See APELES.M).
  * Quantization using a statistical VQ needs:
         señal,Ncuan,opc = 2,B,bitmax,fchest,fc,cc,crit,frecbaja
         (fchest(fichero estadisticas con vari, ff, FF).)

 If using a precomputed VQ (opc = 0), it needs:
         señal,Ncuan,opc = 0,niveles,fronteras,fc,cc,crit,frecbaja.

 We can choose between different DCT normalization:

   Norm = 1 ......... Normalizing using the mean luminance in each patch.

   Norm = 2 ......... Normalizing using the mean luminance in each patch and the neighbour patches.
                      The number of neighbour patches are introduced as parameter.

   Norm = 3 ......... Normalizing using the mean luminance in the whole image.

   Norm = 4 ......... Normalizing using the variable 'valor' (valor*N^2).

   Norm = 5 ......... Not normalization.

 USE: jpeg91_encoder(s,B,directorio,fichero)

 where:

 s         -> Image
 B         -> Quantization levels
 diretorio -> Folder to store the compressed file
 fichero   -> Name of the compressed file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %
0002 % It employs QDCT55 to quantize the DCTs patches with resolution N from a 2D signal
0003 %
0004 % QDCT55 allows designing the VQ using the IAF or the statistics, or to introduce some other quantizer
0005 % previously design (contains APELES Y VQPERC, y QDCT21)
0006 %
0007 % Introduce 1 in the 'opc' variable to compute the PERCEPTUAL VQ.
0008 % Then you need to give the the needed parameters to the function (See VQPERC.m).
0009 %  * Quantization using a perceptual VQ needs:
0010 %         señal,Ncuan,opc = 1,facfrec,ncontr,nolin,estab,
0011 %           B,bitmax,fc,cc,crit,fijarmax,inclcsf,frecbaja.
0012 %
0013 % Introduce 2 in the 'opc' variable to compute the ESTATISTICAL VQ.
0014 % Then you need to give the the needed parameters to the function (See APELES.M).
0015 %  * Quantization using a statistical VQ needs:
0016 %         señal,Ncuan,opc = 2,B,bitmax,fchest,fc,cc,crit,frecbaja
0017 %         (fchest(fichero estadisticas con vari, ff, FF).)
0018 %
0019 % If using a precomputed VQ (opc = 0), it needs:
0020 %         señal,Ncuan,opc = 0,niveles,fronteras,fc,cc,crit,frecbaja.
0021 %
0022 % We can choose between different DCT normalization:
0023 %
0024 %   Norm = 1 ......... Normalizing using the mean luminance in each patch.
0025 %
0026 %   Norm = 2 ......... Normalizing using the mean luminance in each patch and the neighbour patches.
0027 %                      The number of neighbour patches are introduced as parameter.
0028 %
0029 %   Norm = 3 ......... Normalizing using the mean luminance in the whole image.
0030 %
0031 %   Norm = 4 ......... Normalizing using the variable 'valor' (valor*N^2).
0032 %
0033 %   Norm = 5 ......... Not normalization.
0034 %
0035 % USE: jpeg91_encoder(s,B,directorio,fichero)
0036 %
0037 % where:
0038 %
0039 % s         -> Image
0040 % B         -> Quantization levels
0041 % diretorio -> Folder to store the compressed file
0042 % fichero   -> Name of the compressed file
0043 %
0044 
0045 function jpeg91_encoder(s,B,directorio,fichero)
0046 Ncuan = 4;
0047 opc = 1;
0048 niveles = 0;
0049 fronteras = 0;
0050 facfrec = 1.1;
0051 
0052 ncontr = 100;
0053 nolin = 0;
0054 estab = 0;
0055 bitmax = 10;
0056 met = 0;
0057 fchest = 0;
0058 fc = 32;
0059 cc = 1;
0060 crit = 1;
0061 fijarmax = 0;
0062 inclcsf = [1 1];
0063 frecbaja = 0.001;
0064 calcent = 1;
0065 
0066 norm = [3 mean(mean(s))];
0067 MM = 0.8;
0068 
0069 tam = size(s);
0070 tam = tam(1);
0071 lados = [tam tam];
0072 imq = zeros(tam,tam);
0073 dctq = zeros(tam,tam);
0074 codq = zeros(tam,tam);
0075 lcuan = tam/(2^Ncuan);
0076 posai = [tam tam]/2-round(tam/2);
0077 posbd = [tam tam]/2+round(tam/2);
0078 coorcuanai = floor([(posai(1)-1)/lcuan+1 (posai(2)-1)/lcuan+1]);
0079 coorcuanbd = floor([(posbd(1)-1)/lcuan+1 (posbd(2)-1)/lcuan+1]);
0080 if coorcuanai(1)<1
0081     coorcuanai(1)=1;
0082 end
0083 if coorcuanai(2)<1
0084     coorcuanai(2)=1;
0085 end
0086 if coorcuanbd(1)>(2^Ncuan)
0087     coorcuanbd(1)=2^Ncuan;
0088 end
0089 if coorcuanai(2)>(2^Ncuan)
0090     coorcuanbd(2)=2^Ncuan;
0091 end
0092 H=0;
0093 Hi=0;
0094 if (opc==2)
0095     [iaf,ciaf1D,niveles,fronteras]=apeles(B,bitmax,met,fchest);
0096     if inclcsf(1) == 1
0097         [ciaf1Dp,iafp,nuqfp,nivelesp,fronterasp] = vqperc(lcuan,facfrec,ncontr,nolin,estab,B,bitmax,fc,fijarmax,0);
0098         fronterasp = fronterasp*(lcuan^2)*128;
0099 
0100         tamfro = size(fronteras);
0101         for i = 1:tamfro(1)
0102             if niveles(i,1) ~= -1
0103                 condic = (fronteras(i,:) <= (inclcsf(2)*fronterasp(i,1)));
0104                 if (sum(condic) ~= 0)
0105                     v = find(condic<1);
0106                     l = length(v);
0107                     if l>1
0108                         front = [fronteras(i,v) maxi(fronteras(i,:))*ones(1,tamfro(2)-l)];
0109                         nivel = [0 niveles(i,v(2:l)) maxi(niveles(i,:))*ones(1,tamfro(2)-l+1)];
0110                         fronteras(i,:) = front;
0111                         niveles(i,:) = nivel;
0112                     else
0113                         fronteras(i,:) = maxi(fronteras(i,:))*ones(1,tamfro(2));
0114                         niveles(i,:) = [0 maxi(niveles(i,:))*ones(1,tamfro(2))];
0115                     end
0116                 end
0117             else
0118                 fronteras(i,:) = fronteras(i,:);
0119                 niveles(i,:) = niveles(i,:);
0120             end
0121         end
0122     end
0123 elseif (opc == 1)
0124     [ciaf1D,iaf,nuqf,niveles,fronteras] = vqperc(lcuan,facfrec,ncontr,nolin,estab,B,bitmax,fc,fijarmax,0);
0125 end
0126 
0127 dcti = dct2r(s,Ncuan);
0128 
0129 [a,Lm] = contras2(dcti,Ncuan,norm);
0130 
0131 pes = ones(lcuan,lcuan);
0132 pes(1,1) = 0;
0133 
0134 pes=[pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes];
0135 pes=[pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes];
0136 a = pes.*a;
0137 
0138 W = 1;
0139 
0140 val_r = 100;
0141 
0142 e = imdpcm(Lm,W,val_r);
0143 
0144 Nc = round(0.9 * 40);
0145 me = mini(e);
0146 Me = maxi(e);
0147 extr_err = [me Me];
0148 QE = round((Nc -1) * (e - me) / (Me - me));
0149 
0150 Lb = 16;
0151 Li = 256;
0152 codigazo = [];
0153 for i = 1:Lb:Li
0154     for j = 1:Lb:Li
0155         cub = zeros(Lb,Lb);
0156         cub = a(i:(i+(Lb-1)),j:(j+(Lb-1)));
0157         fre = topolar3(fc,Lb);
0158         cond = fre > frecbaja;
0159         tfs = cub;
0160         tfs = tfs .* cond;
0161         tfc = zeros(Lb,Lb);
0162         cod = zeros(Lb,Lb);
0163         for i1 = 1:Lb,
0164             for j1 = 1:Lb,
0165                 d = floor(sqrt((i1-1).^2+(j1-1).^2));
0166                 [tfc(i1,j1),cod(i1,j1)] = asignbbb(abs(tfs(i1,j1)),niveles(d+1,:),fronteras(d+1,:),crit);
0167 
0168             end
0169         end
0170         c1 = (cub >= 0);
0171         c2 = (cub <  0);
0172         tfc = c1.*tfc - c2.*tfc;
0173         anticond = cond < 1;
0174         dctc = cc .* anticond .* cub + cond.*tfc;
0175 
0176         dctc = round(2^B * dctc / MM);
0177         bloque = zigzag(dctc);
0178         bloque = bloque(2:end);
0179 
0180         [codigo,ceros] = rle2(bloque);
0181         codigazo = [codigazo codigo ceros];
0182     end
0183 end
0184 
0185 ristra = [mean(mean(s)) extr_err(:)' round(QE(:))' B round(codigazo)];
0186 
0187 cd(directorio);
0188 save_code_jpeg91(ristra,[fichero '.bin']);
0189 zip(fichero,[fichero '.bin']);
0190 
0191 delete([fichero '.bin']);

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