0001 0002 function [Results]=svr_nl_c_decoder_cs(normaliz,To,dUmax,dVmax,K,exponentes,tipo_alfa,directorio,fichero) 0003 0004 you_are_here=pwd; 0005 0006 cd(directorio) 0007 unzip([fichero '.zip']); 0008 ristra = read_code([fichero '.bin']); 0009 0010 delete([fichero '.bin']); 0011 0012 TheCode=zeros(256,255,3); 0013 0014 posicion=length(ristra); 0015 queda_ristra=ristra; 0016 for cap=3:-1:1 0017 0018 if cap==1 0019 for i=256:-1:1 0020 0021 queda_ristra=ristra(1:posicion); 0022 ceros=find(queda_ristra==0); 0023 pos_cero=ceros(end); 0024 ceros_bloque=queda_ristra(pos_cero+1:end); 0025 queda_ristra=queda_ristra(1:pos_cero); 0026 posicion=pos_cero; 0027 0028 bloque=[]; 0029 0030 long_bloque=0; 0031 0032 while long_bloque<255 0033 0034 dato=queda_ristra(posicion); 0035 queda_ristra=queda_ristra(1:end-1); 0036 posicion=posicion-1; 0037 if dato==0 0038 bloque=[zeros(1,ceros_bloque(end)) bloque]; 0039 ceros_bloque=ceros_bloque(1:end-1); 0040 long_bloque=length(bloque); 0041 else 0042 bloque=[dato bloque]; 0043 long_bloque=length(bloque); 0044 end 0045 0046 end 0047 TheCode(i,:,cap)=bloque; 0048 end 0049 else 0050 for i=256:-1:1 0051 0052 queda_ristra=ristra(1:posicion); 0053 ceros=find(queda_ristra==0); 0054 pos_cero=ceros(end); 0055 ceros_bloque=queda_ristra(pos_cero+1:end); 0056 queda_ristra=queda_ristra(1:pos_cero); 0057 posicion=pos_cero; 0058 0059 bloque=[]; 0060 0061 long_bloque=0; 0062 0063 while long_bloque<63 0064 0065 dato=queda_ristra(posicion); 0066 queda_ristra=queda_ristra(1:end-1); 0067 posicion=posicion-1; 0068 if dato==0 0069 bloque=[zeros(1,ceros_bloque(end)) bloque]; 0070 ceros_bloque=ceros_bloque(1:end-1); 0071 long_bloque=length(bloque); 0072 else 0073 bloque=[dato bloque]; 0074 long_bloque=length(bloque); 0075 end 0076 0077 end 0078 blo=zeros(16,16); 0079 bloo=[0 bloque]; 0080 bloo=dezigzag(bloo); 0081 blo(1:8,1:8)=bloo; 0082 bloque=zigzag(blo); 0083 bloque=bloque(2:end); 0084 TheCode(i,:,cap)=bloque; 0085 end 0086 end 0087 end 0088 0089 bits=queda_ristra(end-2:end); 0090 0091 NumNiv=2.^bits; 0092 MM=0.8; 0093 0094 TheRealCode=TheCode; 0095 for cap=1:3 0096 TheRealCode(:,:,cap)=TheCode(:,:,cap)*MM/NumNiv(cap); 0097 end 0098 0099 queda_ristra=queda_ristra(1:end-3); 0100 QE=queda_ristra(7:end); 0101 QQEE(:,:,1)=reshape(QE(1:256),16,16); 0102 QQEE(:,:,2)=reshape(QE(257:512),16,16); 0103 QQEE(:,:,3)=reshape(QE(513:end),16,16); 0104 0105 extr_err=zeros(2,3); 0106 extr_err(:,1)=queda_ristra(1:2)'; 0107 extr_err(:,2)=queda_ristra(3:4)'; 0108 extr_err(:,3)=queda_ristra(5:6)'; 0109 0110 N=round(0.9*[40 10 10]); 0111 for i=1:3 0112 qe(:,:,i)=(extr_err(2,i)-extr_err(1,i))*QQEE(:,:,i)/(N(i)-1)+extr_err(1,i); 0113 end 0114 0115 for i=1:3 0116 Lmq(:,:,i)=iimdpcm(qe(:,:,i),1,To(i)); 0117 end 0118 0119 Li = 256; 0120 Lb = 16; 0121 0122 cero = 1; 0123 0124 [h,alpha,beta,gamm]=constrains_respY(exponentes(1),cero,tipo_alfa); 0125 [hU,alphaU,betaU,gammU]=constrains_respU(exponentes(2),cero); 0126 [hV,alphaV,betaV,gammV]=constrains_respV(exponentes(3),cero); 0127 0128 aa = zeros(Lb); 0129 [h_a,r,GR,alfa2d,beta2d]=respue5(aa,alpha,beta,gamm,h,0); 0130 [h_a,r,GR,alfa2dU,beta2dU]=respue5(aa,alphaU,betaU,gammU,hU,0); 0131 [h_a,r,GR,alfa2dV,beta2dV]=respue5(aa,alphaV,betaV,gammV,hV,0); 0132 0133 fprintf('Recovering the image:\n'); 0134 fprintf(' Inverting from r to dct\n'); 0135 0136 trc(:,:,1) = TheRealCode(:,:,1)'; 0137 trc(:,:,2) = TheRealCode(:,:,2)'; 0138 trc(:,:,3) = TheRealCode(:,:,3)'; 0139 TheRealCode = trc; 0140 0141 Identidad = eye(size(h)); 0142 0143 for cap=1:3 0144 fprintf(' Channel %d: ',cap); 0145 0146 if cap==1 0147 Db=diag(beta2d); 0148 elseif cap==2 0149 Db=diag(beta2dU); 0150 alfa2d=alfa2dU; 0151 gamm=gammU; 0152 h=hU; 0153 else 0154 Db=diag(beta2dV); 0155 alfa2d=alfa2dV; 0156 gamm=gammV; 0157 h=hV; 0158 end 0159 0160 z = 1; 0161 0162 for i=1:Lb:(Li-1) 0163 fprintf('.'); 0164 0165 for j=1:Lb:(Li-1) 0166 0167 r_recon=K*TheRealCode(:,z,cap); 0168 0169 signosr = r_recon<0; 0170 0171 r_recon = [0; abs(r_recon)]; 0172 0173 Dr=diag(r_recon); 0174 0175 ac = ((inv(Identidad-Dr*h)*Db*r_recon).^(1/gamm))./alfa2d; 0176 0177 ac_c = ac(2:end); 0178 0179 acs = ac_c.*(signosr==0) - ac_c.*(signosr>0); 0180 0181 acs = [0;acs]; 0182 0183 acs=dezigzag(acs); 0184 0185 dctc1(i:(i+(Lb-1)),j:(j+(Lb-1)),cap)=acs; 0186 0187 z=z+1; 0188 end 0189 end 0190 fprintf('\n'); 0191 end 0192 fprintf('\n'); 0193 0194 fprintf(' Inverting from dct to spatial domain\n'); 0195 0196 Ncuan = 4; 0197 0198 dctc1i=icontras3(dctc1,Lmq,Ncuan,normaliz,To,dUmax,dVmax); 0199 0200 for cap=1:3 0201 ImRyuv(:,:,cap)=real(idct2r(dctc1i(:,:,cap),Ncuan)); 0202 end 0203 0204 ImR=my_yuv2rgb(ImRyuv); 0205 0206 Results = uint8(ImR); 0207 0208 cd(you_are_here)