001/* 002 * $RCSfile: AnWTFilterIntLift5x3.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:29 $ 005 * $State: Exp $ 006 * 007 * Class: AnWTFilterIntLift5x3 008 * 009 * Description: An analyzing wavelet filter implementing the 010 * lifting 5x3 transform. 011 * 012 * 013 * 014 * COPYRIGHT: 015 * 016 * This software module was originally developed by Raphaël Grosbois and 017 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel 018 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David 019 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research 020 * Centre France S.A) in the course of development of the JPEG2000 021 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This 022 * software module is an implementation of a part of the JPEG 2000 023 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio 024 * Systems AB and Canon Research Centre France S.A (collectively JJ2000 025 * Partners) agree not to assert against ISO/IEC and users of the JPEG 026 * 2000 Standard (Users) any of their rights under the copyright, not 027 * including other intellectual property rights, for this software module 028 * with respect to the usage by ISO/IEC and Users of this software module 029 * or modifications thereof for use in hardware or software products 030 * claiming conformance to the JPEG 2000 Standard. Those intending to use 031 * this software module in hardware or software products are advised that 032 * their use may infringe existing patents. The original developers of 033 * this software module, JJ2000 Partners and ISO/IEC assume no liability 034 * for use of this software module or modifications thereof. No license 035 * or right to this software module is granted for non JPEG 2000 Standard 036 * conforming products. JJ2000 Partners have full right to use this 037 * software module for his/her own purpose, assign or donate this 038 * software module to any third party and to inhibit third parties from 039 * using this software module for non JPEG 2000 Standard conforming 040 * products. This copyright notice must be included in all copies or 041 * derivative works of this software module. 042 * 043 * Copyright (c) 1999/2000 JJ2000 Partners. 044 * */ 045package jj2000.j2k.wavelet.analysis; 046 047import jj2000.j2k.wavelet.FilterTypes; 048 049/** 050 * This class inherits from the analysis wavelet filter definition for int 051 * data. It implements the forward wavelet transform specifically for the 5x3 052 * filter. The implementation is based on the lifting scheme. 053 * 054 * <P>See the AnWTFilter class for details such as normalization, how to split 055 * odd-length signals, etc. In particular, this method assumes that the 056 * low-pass coefficient is computed first. 057 * 058 * @see AnWTFilter 059 * @see AnWTFilterInt 060 * */ 061public class AnWTFilterIntLift5x3 extends AnWTFilterInt { 062 063 /** The low-pass synthesis filter of the 5x3 wavelet transform */ 064 private final static float LPSynthesisFilter[] = 065 { 0.5f, 1f, 0.5f }; 066 067 /** The high-pass synthesis filter of the 5x3 wavelet transform */ 068 private final static float HPSynthesisFilter[] = 069 { -0.125f, -0.25f, 0.75f, -0.25f, -0.125f }; 070 071 /** 072 * An implementation of the analyze_lpf() method that works on int data, 073 * for the forward 5x3 wavelet transform using the lifting scheme. See the 074 * general description of the analyze_lpf() method in the AnWTFilter class 075 * for more details. 076 * 077 * <P>The coefficients of the first lifting step are [-1/2 1 -1/2]. 078 * 079 * <P>The coefficients of the second lifting step are [1/4 1 1/4]. 080 * 081 * @param inSig This is the array that contains the input 082 * signal. 083 * 084 * @param inOff This is the index in inSig of the first sample to 085 * filter. 086 * 087 * @param inLen This is the number of samples in the input signal 088 * to filter. 089 * 090 * @param inStep This is the step, or interleave factor, of the 091 * input signal samples in the inSig array. 092 * 093 * @param lowSig This is the array where the low-pass output 094 * signal is placed. 095 * 096 * @param lowOff This is the index in lowSig of the element where 097 * to put the first low-pass output sample. 098 * 099 * @param lowStep This is the step, or interleave factor, of the 100 * low-pass output samples in the lowSig array. 101 * 102 * @param highSig This is the array where the high-pass output 103 * signal is placed. 104 * 105 * @param highOff This is the index in highSig of the element where 106 * to put the first high-pass output sample. 107 * 108 * @param highStep This is the step, or interleave factor, of the 109 * high-pass output samples in the highSig array. 110 * */ 111 public 112 void analyze_lpf(int inSig[], int inOff, int inLen, int inStep, 113 int lowSig[], int lowOff, int lowStep, 114 int highSig[], int highOff, int highStep) { 115 int i; 116 int iStep = 2 * inStep; //Subsampling in inSig 117 int ik; //Indexing inSig 118 int lk; //Indexing lowSig 119 int hk; //Indexing highSig 120 121 /* 122 *Generate high frequency subband 123 */ 124 125 //Initialize counters 126 ik = inOff + inStep; 127 hk = highOff; 128 129 //Apply first lifting step to each "inner" sample. 130 for(i = 1; i < inLen-1; i += 2) { 131 highSig[hk] = inSig[ik] - 132 ((inSig[ik-inStep] + inSig[ik+inStep])>>1); 133 134 ik += iStep; 135 hk += highStep; 136 } 137 138 //Handle head boundary effect if input signal has even length. 139 if( inLen % 2 == 0 ) { 140 highSig[hk] = inSig[ik] - ((2*inSig[ik-inStep])>>1); 141 } 142 143 /* 144 *Generate low frequency subband 145 */ 146 147 //Initialize counters 148 ik = inOff; 149 lk = lowOff; 150 hk = highOff; 151 152 if(inLen>1) { 153 lowSig[lk] = inSig[ik] + ((highSig[hk] + 1)>>1); 154 } 155 else { 156 lowSig[lk] = inSig[ik]; 157 } 158 159 ik += iStep; 160 lk += lowStep; 161 hk += highStep; 162 163 //Apply lifting step to each "inner" sample. 164 for(i = 2; i < inLen-1; i += 2) { 165 lowSig[lk] = inSig[ik] + 166 ((highSig[hk-highStep] + highSig[hk] + 2)>> 2); 167 168 ik += iStep; 169 lk += lowStep; 170 hk += highStep; 171 } 172 173 //Handle head boundary effect if input signal has odd length. 174 if(inLen % 2 == 1) { 175 if(inLen>2) { 176 lowSig[lk] = inSig[ik] + ((2*highSig[hk-highStep]+2)>>2); 177 } 178 } 179 } 180 181 /** 182 * An implementation of the analyze_hpf() method that works on int data, 183 * for the forward 5x3 wavelet transform using the lifting scheme. See the 184 * general description of the analyze_hpf() method in the AnWTFilter class 185 * for more details. 186 * 187 * <P>The coefficients of the first lifting step are [-1/2 1 -1/2]. 188 * 189 * <P>The coefficients of the second lifting step are [1/4 1 1/4]. 190 * 191 * @param inSig This is the array that contains the input 192 * signal. 193 * 194 * @param inOff This is the index in inSig of the first sample to 195 * filter. 196 * 197 * @param inLen This is the number of samples in the input signal 198 * to filter. 199 * 200 * @param inStep This is the step, or interleave factor, of the 201 * input signal samples in the inSig array. 202 * 203 * @param lowSig This is the array where the low-pass output 204 * signal is placed. 205 * 206 * @param lowOff This is the index in lowSig of the element where 207 * to put the first low-pass output sample. 208 * 209 * @param lowStep This is the step, or interleave factor, of the 210 * low-pass output samples in the lowSig array. 211 * 212 * @param highSig This is the array where the high-pass output 213 * signal is placed. 214 * 215 * @param highOff This is the index in highSig of the element where 216 * to put the first high-pass output sample. 217 * 218 * @param highStep This is the step, or interleave factor, of the 219 * high-pass output samples in the highSig array. 220 * 221 * @see AnWTFilter#analyze_hpf 222 * */ 223 public 224 void analyze_hpf(int inSig[], int inOff, int inLen, int inStep, 225 int lowSig[], int lowOff, int lowStep, 226 int highSig[], int highOff, int highStep) { 227 int i; 228 int iStep = 2 * inStep; //Subsampling in inSig 229 int ik; //Indexing inSig 230 int lk; //Indexing lowSig 231 int hk; //Indexing highSig 232 233 /* 234 *Generate high frequency subband 235 */ 236 237 //Initialize counters 238 ik = inOff; 239 hk = highOff; 240 241 if ( inLen>1 ) { 242 // apply a symmetric extension. 243 highSig[hk] = inSig[ik] - inSig[ik+inStep]; 244 } 245 else { 246 // Normalize for Nyquist gain 247 highSig[hk] = inSig[ik]<<1; 248 } 249 250 ik += iStep; 251 hk += highStep; 252 253 //Apply first lifting step to each "inner" sample. 254 if ( inLen>3 ) { 255 for(i = 2; i < inLen-1; i += 2) { 256 highSig[hk] = inSig[ik] - 257 ((inSig[ik-inStep] + inSig[ik+inStep])>>1); 258 ik += iStep; 259 hk += highStep; 260 } 261 } 262 263 //If input signal has odd length then we perform the lifting step 264 // i.e. apply a symmetric extension. 265 if( inLen%2==1 && inLen>1 ) { 266 highSig[hk] = inSig[ik] - inSig[ik-inStep]; 267 } 268 269 /* 270 *Generate low frequency subband 271 */ 272 273 //Initialize counters 274 ik = inOff + inStep; 275 lk = lowOff; 276 hk = highOff; 277 278 for (i=1 ; i<inLen-1 ; i+=2) { 279 280 lowSig[lk] = inSig[ik] + 281 ((highSig[hk] + highSig[hk+highStep] + 2)>> 2); 282 283 ik += iStep; 284 lk += lowStep; 285 hk += highStep; 286 } 287 288 if ( inLen>1 && inLen%2==0) { 289 // apply a symmetric extension. 290 lowSig[lk] = inSig[ik]+((2*highSig[hk]+2)>>2); 291 } 292 } 293 /** 294 * Returns the negative support of the low-pass analysis 295 * filter. That is the number of taps of the filter in the 296 * negative direction. 297 * 298 * @return 2 299 * */ 300 public int getAnLowNegSupport() { 301 return 2; 302 } 303 304 /** 305 * Returns the positive support of the low-pass analysis filter. That is 306 * the number of taps of the filter in the negative direction. 307 * 308 * @return The number of taps of the low-pass analysis filter in the 309 * positive direction 310 * */ 311 public int getAnLowPosSupport() { 312 return 2; 313 } 314 315 /** 316 * Returns the negative support of the high-pass analysis filter. That is 317 * the number of taps of the filter in the negative direction. 318 * 319 * @return The number of taps of the high-pass analysis filter in 320 * the negative direction 321 * */ 322 public int getAnHighNegSupport() { 323 return 1; 324 } 325 326 /** 327 * Returns the positive support of the high-pass analysis filter. That is 328 * the number of taps of the filter in the negative direction. 329 * 330 * @return The number of taps of the high-pass analysis filter in the 331 * positive direction 332 * */ 333 public int getAnHighPosSupport() { 334 return 1; 335 } 336 337 /** 338 * Returns the negative support of the low-pass synthesis filter. That is 339 * the number of taps of the filter in the negative direction. 340 * 341 * <P>A MORE PRECISE DEFINITION IS NEEDED 342 * 343 * @return The number of taps of the low-pass synthesis filter in the 344 * negative direction 345 * */ 346 public int getSynLowNegSupport() { 347 return 1; 348 } 349 350 /** 351 * Returns the positive support of the low-pass synthesis filter. That is 352 * the number of taps of the filter in the negative direction. 353 * 354 * <P>A MORE PRECISE DEFINITION IS NEEDED 355 * 356 * @return The number of taps of the low-pass synthesis filter in 357 * the positive direction 358 * */ 359 public int getSynLowPosSupport() { 360 return 1; 361 } 362 363 /** 364 * Returns the negative support of the high-pass synthesis filter. That is 365 * the number of taps of the filter in the negative direction. 366 * 367 * <P>A MORE PRECISE DEFINITION IS NEEDED 368 * 369 * @return The number of taps of the high-pass synthesis filter in the 370 * negative direction 371 * */ 372 public int getSynHighNegSupport() { 373 return 2; 374 } 375 376 /** 377 * Returns the positive support of the high-pass synthesis filter. That is 378 * the number of taps of the filter in the negative direction. 379 * 380 * <P>A MORE PRECISE DEFINITION IS NEEDED 381 * 382 * @return The number of taps of the high-pass synthesis filter in the 383 * positive direction 384 * */ 385 public int getSynHighPosSupport() { 386 return 2; 387 } 388 389 /** 390 * Returns the time-reversed low-pass synthesis waveform of the filter, 391 * which is the low-pass filter. This is the time-reversed impulse 392 * response of the low-pass synthesis filter. It is used to calculate the 393 * L2-norm of the synthesis basis functions for a particular subband (also 394 * called energy weight). 395 * 396 * <P>The returned array may not be modified (i.e. a reference to the 397 * internal array may be returned by the implementation of this method). 398 * 399 * @return The time-reversed low-pass synthesis waveform of the filter. 400 * */ 401 public float[] getLPSynthesisFilter() { 402 return LPSynthesisFilter; 403 } 404 405 /** 406 * Returns the time-reversed high-pass synthesis waveform of the filter, 407 * which is the high-pass filter. This is the time-reversed impulse 408 * response of the high-pass synthesis filter. It is used to calculate the 409 * L2-norm of the synthesis basis functions for a particular subband (also 410 * called energy weight). 411 * 412 * <P>The returned array may not be modified (i.e. a reference to the 413 * internal array may be returned by the implementation of this method). 414 * 415 * @return The time-reversed high-pass synthesis waveform of the filter. 416 * */ 417 public float[] getHPSynthesisFilter() { 418 return HPSynthesisFilter; 419 } 420 421 422 /** 423 * Returns the implementation type of this filter, as defined in this 424 * class, such as WT_FILTER_INT_LIFT, WT_FILTER_FLOAT_LIFT, 425 * WT_FILTER_FLOAT_CONVOL. 426 * 427 * @return WT_FILTER_INT_LIFT. 428 * */ 429 public int getImplType() { 430 return WT_FILTER_INT_LIFT; 431 } 432 433 /** 434 * Returns the reversibility of the filter. A filter is considered 435 * reversible if it is suitable for lossless coding. 436 * 437 * @return true since the 5x3 is reversible, provided the appropriate 438 * rounding is performed. 439 * */ 440 public boolean isReversible() { 441 return true; 442 } 443 444 /** 445 * Returns true if the wavelet filter computes or uses the same "inner" 446 * subband coefficient as the full frame wavelet transform, and false 447 * otherwise. In particular, for block based transforms with reduced 448 * overlap, this method should return false. The term "inner" indicates 449 * that this applies only with respect to the coefficient that are not 450 * affected by image boundaries processings such as symmetric extension, 451 * since there is not reference method for this. 452 * 453 * <P>The result depends on the length of the allowed overlap when 454 * compared to the overlap required by the wavelet filter. It also depends 455 * on how overlap processing is implemented in the wavelet filter. 456 * 457 * @param tailOvrlp This is the number of samples in the input signal 458 * before the first sample to filter that can be used for overlap. 459 * 460 * @param headOvrlp This is the number of samples in the input signal 461 * after the last sample to filter that can be used for overlap. 462 * 463 * @param inLen This is the lenght of the input signal to filter.The 464 * required number of samples in the input signal after the last sample 465 * depends on the length of the input signal. 466 * 467 * @return true if both overlaps are greater than 2, and correct 468 * processing is applied in the analyze() method. 469 * */ 470 public boolean isSameAsFullWT(int tailOvrlp, int headOvrlp, int inLen) { 471 472 //If the input signal has even length. 473 if( inLen % 2 == 0) { 474 if( tailOvrlp >= 2 && headOvrlp >= 1 ) return true; 475 else return false; 476 } 477 //Else if the input signal has odd length. 478 else { 479 if( tailOvrlp >= 2 && headOvrlp >= 2 ) return true; 480 else return false; 481 } 482 } 483 484 /** 485 * Tests if the 'obj' object is the same filter as this one. Two filters 486 * are the same if the same filter code should be output for both filters 487 * by the encodeFilterCode() method. 488 * 489 * <P>Currently the implementation of this method only tests if 'obj' is 490 * also of the class AnWTFilterIntLift5x3. 491 * 492 * @param The object against which to test inequality. 493 * */ 494 public boolean equals(Object obj) { 495 // To speed up test, first test for reference equality 496 return obj == this || 497 obj instanceof AnWTFilterIntLift5x3; 498 } 499 500 /** 501 * Returns the type of filter used according to the FilterTypes interface 502 * (W5x3). 503 * 504 * @see FilterTypes 505 * 506 * @return The filter type. 507 * */ 508 public int getFilterType(){ 509 return FilterTypes.W5X3; 510 } 511 512 /** Debugging method */ 513 public String toString(){ 514 return "w5x3"; 515 } 516}