调整图像的强度

时间:2017-11-15 02:06:40

标签: java arrays eclipse image

我正在尝试增加灰度图像的强度,同时保持图像的轮廓。我创建的算法只查看每个单元格的左,右,上,下邻居中的值,实际上只有处理阵列的内部单元。显然有代码行和代码行,但是我被抛出ArrayOutOfBoundsException这个块(如果需要,我可以提供所有代码)。有人可以告诉我我的问题是什么,或者提供有关需要重新审视的建议吗?

public Image getEdgeImage(){
    Image edge = new Image(this);
    for(int row = 1; row < numRows; row++) {

        for(int col = 1 ; col < numColumns; col++) {

        double Lx = -.5 * edge.pixels[row -1][col].getRed() + (.5 * edge.pixels[row + 1][col].getRed()) ;
        double Ly = -.5 * edge.pixels[row][col -1].getRed() + (.5 * edge.pixels[row][col + 1].getRed());

        int L = (int) Math.sqrt((Lx * Lx) + (Ly * Ly));
        edge.pixels[row][col] = new Color(L, L, L);
        }
    }
    return edge;
}

1 个答案:

答案 0 :(得分:0)

如果您获得for i in P.inventory: counter = 0 if i == Book(): print("You have a book.") counter = 1 if counter == 0: print("You don't have a book.") ,请按照ArrayOutOfBoundException索引观察您访问数组元素的区域。

在您的计划中,第5行&amp; 6,你指责下一个元素没有检查数组长度。

+/-

enter image description here

数组索引将从 edge.pixels[row + 1] edge.pixels[row][col + 1] 开始到0,假设您的数组的长度为length-1,并且在10次迭代中,您的程序将检查索引{第1行和第6行{1}}上面突出显示的代码。