0

我正在使用 Java Swing 在 Netbeans 中制作应用程序。我想在我的应用程序中实现一些图像处理功能(如在 ImageJ 中),而不使用 ImageJ、JAI 和 jhlab 库。

例如:ImageJ>>Process>>Noise>>Despeckle。

那么,我该怎么做呢?

4

1 回答 1

2

这可能有帮助

private void removeNoise() {
    int iterator;

    for (int row = 0; row < x1; row++) {
        for (int column = 0; column < y1; column++) {
            if (row == 0 || row == x1 - 1 || column == 0
                    || column == y1 - 1) {
                result[row][column] = result[row][column];
                continue;
            } else {
                iterator = 0;
                for (int r = row - 1; r < row + 2; r++) {
                    for (int c = column - 1; c < column + 2; c++) {
                        surround[iterator] = result[r][c];
                        iterator++;
                    }
                }
                result[row][column] =
                        sortMedian(surround, 9);  //calls the sorting method

            }

        }
    }
    setPixel();
}

private int sortMedian(int[] surround1, int x) {
    int i, j, t = 0;
    for (i = 0; i < 9; i++) {
        for (j = 1; j < (9 - i); j++) {
            if (surround1[j - 1] > surround1[j]) {
                t = surround1[j - 1];
                surround1[j - 1] = surround1[j];
                surround1[j] = t;
            }
        }
    }
    return surround1[4];
}

private void setPixel() {
    int[] pixel = new int[1];

    for (int x = 0; x < bi.getWidth(); x++) {
        for (int y = 0; y < bi.getHeight(); y++) {

            pixel[0] = (int) result[x][y];


              rnImage.getRaster().setPixel(x, y, pixel);

            }
        }
    }
于 2012-04-20T13:53:37.440 回答