0

我有一个任务,我试图在图像中产生噪音,类似于我在这里所做的:

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) - 传递一个二维数组 shorts 代表图像,另一个 short 是要从图像中添加或减去的噪声量。- 返回一个 2D 短裤数组,即变暗图像

4

1 回答 1

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;
}
于 2014-03-16T20:30:46.680 回答