使用2D数组和循环为PGM图像添加噪声?

时间:2014-03-16 19:28:06

标签: java arrays 2d noise pgm

我有一个作业,我试图在图像中创建噪声,就像我在这里做的那样:

public static short[][] brighten(short[][] orig, short amount) {

    short[][] returnArray = new short[orig.length][orig[0].length];
    for(int i = 0; i < orig.length; ++i){
        for(int j = 0; j < orig[0].length; ++j){
            returnArray[i][j] = (short)(orig[i][j]+amount);
        }

    }
    return returnArray;
}

说明: public short [] [] Noise(short [] [],short) - 传递一个代表图像的二维短裤阵列和另一个短片,它是从图像中添加或减去的噪声量。 - 返回一个2D阵列的短裤,这是一个黑暗的图像 - 对于数组中的每个项目,随机添加或减去随机值直到短参数

1 个答案:

答案 0 :(得分:0)

除了缺失的随机性,我没有看到任何问题,所以我认为这是关于这个:

public static short[][] brighten(short[][] orig, short amount) {
    Random random = new Random();
    short[][] returnArray = new short[orig.length][orig[0].length];
    for(int i = 0; i < orig.length; ++i){
        for(int j = 0; j < orig[0].length; ++j){
            int randomValue = -amount + random.nextInt(amount+amount);
            returnArray[i][j] = (short)(orig[i][j]+randomValue);
        }
    }
    return returnArray;
}
相关问题