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 malo99_encoder(s,B,directorio,fichero)
0045 Ncuan = 4;
0046 opc = 1;
0047 niveles = 0;
0048 fronteras = 0;
0049 facfrec = 1;
0050
0051 ncontr = 100;
0052 nolin = 1;
0053 estab = 0;
0054 bitmax = 10;
0055 met = 0;
0056 fchest = 0;
0057 fc = 32;
0058 cc = 1;
0059 crit = 1;
0060 fijarmax = 0;
0061 inclcsf = [1 1];
0062 frecbaja = 0.001;
0063
0064 norm = [3 mean(mean(s))];
0065 MM = 0.8;
0066
0067 tam = size(s);
0068 tam = tam(1);
0069 lados = [tam tam];
0070 imq = zeros(tam,tam);
0071 dctq = zeros(tam,tam);
0072 codq = zeros(tam,tam);
0073 lcuan = tam/(2^Ncuan);
0074 posai = [tam tam]/2-round(tam/2);
0075 posbd = [tam tam]/2+round(tam/2);
0076 coorcuanai = floor([(posai(1)-1)/lcuan+1 (posai(2)-1)/lcuan+1]);
0077 coorcuanbd = floor([(posbd(1)-1)/lcuan+1 (posbd(2)-1)/lcuan+1]);
0078 if coorcuanai(1)<1
0079 coorcuanai(1)=1;
0080 end
0081 if coorcuanai(2)<1
0082 coorcuanai(2)=1;
0083 end
0084 if coorcuanbd(1)>(2^Ncuan)
0085 coorcuanbd(1)=2^Ncuan;
0086 end
0087 if coorcuanai(2)>(2^Ncuan)
0088 coorcuanbd(2)=2^Ncuan;
0089 end
0090 H=0;
0091 Hi=0;
0092 if (opc==2)
0093 [iaf,ciaf1D,niveles,fronteras]=apeles(B,bitmax,met,fchest);
0094 if inclcsf(1) == 1
0095 [ciaf1Dp,iafp,nuqfp,nivelesp,fronterasp] = vqperc(lcuan,facfrec,ncontr,nolin,estab,B,bitmax,fc,fijarmax,0);
0096 fronterasp = fronterasp*(lcuan^2)*128;
0097
0098 tamfro = size(fronteras);
0099 for i = 1:tamfro(1)
0100 if niveles(i,1) ~= -1
0101 condic = (fronteras(i,:) <= (inclcsf(2)*fronterasp(i,1)));
0102 if (sum(condic) ~= 0)
0103 v = find(condic<1);
0104 l = length(v);
0105 if l>1
0106 front = [fronteras(i,v) maxi(fronteras(i,:))*ones(1,tamfro(2)-l)];
0107 nivel = [0 niveles(i,v(2:l)) maxi(niveles(i,:))*ones(1,tamfro(2)-l+1)];
0108 fronteras(i,:) = front;
0109 niveles(i,:) = nivel;
0110 else
0111 fronteras(i,:) = maxi(fronteras(i,:))*ones(1,tamfro(2));
0112 niveles(i,:) = [0 maxi(niveles(i,:))*ones(1,tamfro(2))];
0113 end
0114 end
0115 else
0116 fronteras(i,:) = fronteras(i,:);
0117 niveles(i,:) = niveles(i,:);
0118 end
0119 end
0120 end
0121 elseif (opc == 1)
0122 [ciaf1D,iaf,nuqf,niveles,fronteras] = vqperc(lcuan,facfrec,ncontr,nolin,estab,B,bitmax,fc,fijarmax,0);
0123 end
0124
0125 dcti = dct2r(s,Ncuan);
0126
0127 [a,Lm] = contras2(dcti,Ncuan,norm);
0128
0129 pes = ones(lcuan,lcuan);
0130 pes(1,1) = 0;
0131
0132 pes=[pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes];
0133 pes=[pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes];
0134 a = pes.*a;
0135
0136 W = 1;
0137
0138 val_r = 100;
0139
0140 e = imdpcm(Lm,W,val_r);
0141
0142 Nc = round(0.9 * 40);
0143 me = mini(e);
0144 Me = maxi(e);
0145 extr_err = [me Me];
0146 QE = round((Nc -1) * (e - me) / (Me - me));
0147
0148 Lb = 16;
0149 Li = 256;
0150 codigazo = [];
0151 for i = 1:Lb:Li
0152 for j = 1:Lb:Li
0153 cub = zeros(Lb,Lb);
0154 cub = a(i:(i+(Lb-1)),j:(j+(Lb-1)));
0155 fre = topolar3(fc,Lb);
0156 cond = fre > frecbaja;
0157 tfs = cub;
0158 tfs = tfs .* cond;
0159 tfc = zeros(Lb,Lb);
0160 cod = zeros(Lb,Lb);
0161 for i1 = 1:Lb,
0162 for j1 = 1:Lb,
0163 d = floor(sqrt((i1-1).^2+(j1-1).^2));
0164 [tfc(i1,j1),cod(i1,j1)] = asignbbb(abs(tfs(i1,j1)),niveles(d+1,:),fronteras(d+1,:),crit);
0165 end
0166 end
0167 c1 = (cub >= 0);
0168 c2 = (cub < 0);
0169 tfc = c1.*tfc - c2.*tfc;
0170 anticond = cond < 1;
0171 dctc = cc .* anticond .* cub + cond.*tfc;
0172
0173 dctc = round(2^B * dctc / MM);
0174 bloque = zigzag(dctc);
0175 bloque = bloque(2:end);
0176
0177 [codigo,ceros] = rle2(bloque);
0178 codigazo = [codigazo codigo ceros];
0179 end
0180 end
0181
0182 ristra = [mean(mean(s)) extr_err(:)' round(QE(:))' B round(codigazo)];
0183
0184 cd(directorio);
0185 save_code_malo99(ristra,[fichero '.bin']);
0186 zip(fichero,[fichero '.bin']);
0187
0188 delete([fichero '.bin']);
0189