7. แถวลำดับ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 7-32  เมท็อดการทำ matrix convolution
  public static int[][] convolute(int[][] p, int[][] f, int bias) {
    int[][] out = new int[p.length][p[0].length];
    int sum = 0;
    for (int i = 0; i < f.length; i++)
      for (int j = 0; j < f[0].length; j++)
        sum += f[i][j];
    for (int x = 1; x < p.length - 1; x++) {
      for (int y = 1; y < p[0].length - 1; y++) {
        int r = 0, g = 0, b = 0;
        for (int i = 0; i <= 2; i++) {
          for (int j = 0; j <= 2; j++) {
            r += f[i][j] * DWindow.getR(p[x+i-1][y+j-1]);
            g += f[i][j] * DWindow.getG(p[x+i-1][y+j-1]);
            b += f[i][j] * DWindow.getB(p[x+i-1][y+j-1]);
          }
        }
        if (sum != 0) {  
          r /= sum; g /= sum; b /= sum;
        } else {
          r += bias; g += bias; b += bias;
        }
        out[x][y] = DWindow.mixRGB(r, g, b);
      }
    }
    return out;
  }
©2009 S.Prasitjutrakul