⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idwt.java

📁 这是DWT和IDWT的源码. 离散小波的原始程式。
💻 JAVA
字号:
/*
 ****************************************************************************
 *
 *   Transform a wavelet integer image into a grayscale image.
 *
 ****************************************************************************
 */
import java.io.*;

public class IDwt {

  public static void main(String[] args) {
    int  level, nrows, ncols, img[][], source[][], result[][];
    int  i, j, i2, j2, k, nr, nc, nr2, nc2, tmp;

    if (args.length != 5) {
      System.out.println(
        "Usage: IDwt <level> <nrows> <ncols> <in_array> <out_img>");
      System.exit(0);
    }
    // Command line processing:
    if ((level=Integer.parseInt(args[0])) <= 0) {
      System.out.println("Number of levels should be greater than 0\n");
      System.exit(0);
    }
    nrows  = Integer.parseInt(args[1]);
    ncols  = Integer.parseInt(args[2]);
    if (nrows != ncols) {
      System.out.println("Should be a square image\n");
      System.exit(0);
    }

    img = new int[nrows][ncols];
    source = new int[nrows][ncols];
    ArrayIO.readIntArray(args[3], source, nrows, ncols);
    result = new int[nrows][ncols];

    tmp = (int)Math.pow(2, level-1);
    nr = nrows/tmp;
    nc = ncols/tmp;

    for (k=level; k>=1; k--, nr*=2, nc*=2) {
      // Vertical processing:
      nr2 = nr/2;
      for (i=0; i<nr2; i++) {
        for (j=0; j<nc; j++) {
          i2 = i*2;
          result[i2][j]   = (source[i][j] + source[nr2+i][j])/2;
          result[i2+1][j] = (source[i][j] - source[nr2+i][j])/2;
        }
      }
      // Copy to source:
      for (i=0; i<nr; i++)
        for (j=0; j<nc; j++)
          source[i][j] = result[i][j];
      // Horizontal processing:
      nc2 = nc/2;
      for (i=0; i<nr; i++) {
        for (j=0; j<nc2; j++) {
          j2 = j*2;
          result[i][j2]   = (source[i][j] + source[i][nc2+j])/2;
          result[i][j2+1] = (source[i][j] - source[i][nc2+j])/2;
        }
      }
      // Copy to source:
      for (i=0; i<nr; i++)
        for (j=0; j<nc; j++)
          source[i][j] = result[i][j];
    } // End of "for k ..."

    for (i=0; i<nrows; i++)
      for (j=0; j<ncols; j++)
        if (source[i][j] > 255)
          img[i][j] = 255;
        else if (source[i][j] < 0)
          img[i][j] = 0;
        else
          img[i][j] = source[i][j];

    ArrayIO.writeByteArray(args[4], img, nrows, ncols);
  }

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -