Use QDCT65 to quantize the normalized DCTs of a subblock of a 2D signal (Currently 256 * 256 resolution 4) Differences from previous versions : - Use the proper normalization of contrasts ( contras2 rather than contrast ) - Designs the normalization Kernel taking proper care of the DC component. - Including in one function constants from naka8 and naka100 ( With exponent 2 - naka8 - or 'optimized' exponent - 0.98 - naka100 ) Use one or the other parameters as a function of the value of the variable Exp: Exp = 2 -> values naka8 Exp = 1 - > values naka100 - Calculate the parameters once ( constantes_resp ) and then passes them to calculation of the response function ( respue5 ) . Difference of QDCT62 that allows you to not calculate the eigenvalues of the original (if you're not interested in them, it saves time !) Represents QDCT62 signal in a domain with (approx.) statistically uncorrelated characteristics and uncorrelated perceptually (With perceptual metric identity). This is achieved through the divisive normalization: Teo & Heeger, Watson and Simoncelli. This transformation depends on its input signal ( state adaptation ) . It has been shown that this type of response obtains independent statistics ( Simoncelli99 ) and perceptually ( Malo99 ) coefficients , and therefore is a suitable domain for a scalar quantizer . Since the perceptual metric in this domain is the identity apply uniform quantizers and flat bit-allocation per coefficient. For each block the invertibility is checked [max( eig ( D_R * h )) ], and the inverse is computed by using the analytical expression It is normalized to local Michaelson contrast and response according NAKA8.m : Norm = [1 1] ................ Normalized by the average luminance of the subfield considered (local contrast) . Norm = [3 Lm ] ............... Normalized by the fixed value Lm (global contrast) the logical choice is to take Lm = mean ( mean ( Im) ); ( Mean value in digital levels ) Range to distribute the quantization levels in the domain response is given by the maximum diagonal gradient ( acting on contrasts, belonging to [ -1.1 ] ) . USE : RESP = malo06_encoder(s,B,exp,directorio,fichero,RESP) Where: S -> compressed image B - > Parameter setting of quantization levels Exp -> exponent nonlinearity. You can take the values 1 or 2 directorio -> Place where the compressed file will be stored fichero -> name with which the compressed file will be stored RESP -> Optional parameter : nonlinear transform image In the first execution this parameter may not be available, but in a loop search of a certain entropy or distortion is calculated the first time and avoiding load posterior calculation.
0001 % Use QDCT65 to quantize the normalized DCTs of a subblock of a 2D signal 0002 % (Currently 256 * 256 resolution 4) 0003 % 0004 % Differences from previous versions : 0005 % - Use the proper normalization of contrasts ( contras2 rather than contrast ) 0006 % - Designs the normalization Kernel taking proper care of the DC component. 0007 % - Including in one function constants from naka8 and naka100 0008 % ( With exponent 2 - naka8 - or 'optimized' exponent - 0.98 - naka100 ) 0009 % 0010 % Use one or the other parameters as a function of the value of the variable 0011 % Exp: 0012 % Exp = 2 -> values naka8 0013 % Exp = 1 - > values naka100 0014 % - Calculate the parameters once ( constantes_resp ) and then passes them to 0015 % calculation of the response function ( respue5 ) . 0016 % 0017 % Difference of QDCT62 that allows you to not calculate the eigenvalues of the original 0018 % (if you're not interested in them, it saves time !) 0019 % 0020 % Represents QDCT62 signal in a domain with (approx.) statistically uncorrelated characteristics 0021 % and uncorrelated perceptually (With perceptual metric identity). 0022 % This is achieved through the divisive normalization: Teo & Heeger, Watson and Simoncelli. 0023 % This transformation depends on its input signal ( state adaptation ) . 0024 % It has been shown that this type of response obtains independent statistics ( Simoncelli99 ) and 0025 % perceptually ( Malo99 ) coefficients , and therefore is a suitable domain for 0026 % a scalar quantizer . 0027 % 0028 % Since the perceptual metric in this domain is the identity apply uniform quantizers 0029 % and flat bit-allocation per coefficient. 0030 % 0031 % For each block the invertibility is checked [max( eig ( D_R * h )) ], and the inverse is computed 0032 % by using the analytical expression 0033 % 0034 % It is normalized to local Michaelson contrast and response according NAKA8.m : 0035 % 0036 % Norm = [1 1] ................ Normalized by the average luminance 0037 % of the subfield considered (local contrast) . 0038 % 0039 % Norm = [3 Lm ] ............... Normalized by the fixed value Lm (global contrast) 0040 % the logical choice is to take Lm = mean ( mean ( Im) ); 0041 % ( Mean value in digital levels ) 0042 % 0043 % Range to distribute the quantization levels in the domain response is given 0044 % by the maximum diagonal gradient ( acting on contrasts, belonging to 0045 % [ -1.1 ] ) . 0046 % 0047 % USE : RESP = malo06_encoder(s,B,exp,directorio,fichero,RESP) 0048 % 0049 % Where: 0050 % 0051 % S -> compressed image 0052 % B - > Parameter setting of quantization levels 0053 % Exp -> exponent nonlinearity. You can take the values 1 or 2 0054 % directorio -> Place where the compressed file will be stored 0055 % fichero -> name with which the compressed file will be stored 0056 % RESP -> Optional parameter : nonlinear transform image 0057 % In the first execution this parameter may not be available, 0058 % but in a loop search of a certain entropy or 0059 % distortion is calculated the first time and avoiding load 0060 % posterior calculation. 0061 0062 function RESP=malo06_encoder(s,B,exp,directorio,fichero,RESP) 0063 0064 if nargin<6 0065 RESP=[]; 0066 end 0067 0068 Lb = 16; 0069 Li = 256; 0070 0071 M = 0.8; 0072 cero = 1; 0073 0074 Norm = [3 mean(mean(s))]; 0075 0076 Ncuan = 4; 0077 0078 tam = size(s); 0079 tam = tam(1); 0080 lados = [tam tam]; 0081 lcuan = tam/(2^Ncuan); 0082 posai = [tam tam]/2-round(tam/2); 0083 posbd = [tam tam]/2+round(tam/2); 0084 coorcuanai = floor([(posai(1)-1)/lcuan+1 (posai(2)-1)/lcuan+1]); 0085 coorcuanbd = floor([(posbd(1)-1)/lcuan+1 (posbd(2)-1)/lcuan+1]); 0086 if coorcuanai(1) < 1 0087 coorcuanai(1) = 1; 0088 end 0089 if coorcuanai(2) < 1 0090 coorcuanai(2) = 1; 0091 end 0092 if coorcuanbd(1) > (2^Ncuan) 0093 coorcuanbd(1) = 2^Ncuan; 0094 end 0095 if coorcuanai(2) > (2^Ncuan) 0096 coorcuanbd(2) = 2^Ncuan; 0097 end 0098 0099 pes = ones(lcuan,lcuan); 0100 pes(1,1) = 0; 0101 0102 pes=[pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes pes]; 0103 pes=[pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes;pes]; 0104 0105 dcti = dct2r(s,Ncuan); 0106 0107 [a,Lm] = contras2(dcti,Ncuan,Norm); 0108 0109 a = pes.*a; 0110 0111 W = 1; 0112 0113 val_r = 100; 0114 0115 e = imdpcm(Lm,W,val_r); 0116 0117 Nc = round(0.9 * 40); 0118 0119 me = mini(e); 0120 Me = maxi(e); 0121 0122 extr_err = [me Me]; 0123 0124 QE = round((Nc -1) * (e - me) / (Me - me)); 0125 0126 [h,kk1,kk2,gamm] = constrains_resp(exp,cero); 0127 0128 if nargin<6 0129 fprintf(' Computing the non-linear response'); 0130 end 0131 0132 codigazo = []; 0133 bloquecito = 1; 0134 for i=1:Lb:Li 0135 0136 if nargin<6 0137 fprintf('.'); 0138 end 0139 0140 for j=1:Lb:Li 0141 0142 aa = a(i:(i+(Lb-1)),j:(j+(Lb-1))); 0143 0144 if nargin<6 0145 0146 [h_a,r,GR,alfa2d,beta2d] = respue5(aa,kk1,kk2,gamm,h,0); 0147 0148 r = zigzag(r); 0149 r = r(2:end); 0150 RESP=[RESP r]; 0151 0152 else 0153 r=RESP(:,bloquecito); 0154 end 0155 0156 azig = zigzag(aa); 0157 azigsc = azig(2:end); 0158 0159 cod = round(2^B * r / M); 0160 rc = cod * M / (2^B); 0161 0162 signo1 = sign(azigsc).*(rc~=0) + (rc==0); 0163 0164 codigon = signo1 .* rc; 0165 codigonint = signo1 .* cod; 0166 0167 [codigo,ceros] = rle2(codigonint); 0168 codigazo = [codigazo codigo ceros]; 0169 0170 bloquecito = bloquecito + 1; 0171 0172 end 0173 end 0174 0175 ristra = [mean(mean(s)) extr_err(:)' round(QE(:))' B round(codigazo)]; 0176 0177 cd(directorio); 0178 save_code_malo06(ristra,[fichero '.bin']); 0179 0180 zip(fichero,[fichero '.bin']); 0181 0182 delete([fichero '.bin']);