1次反转后反转图像像素

时间:2017-04-17 12:40:11

标签: java image-processing

我有一段代码,如下所示,我用来反转图像的像素数据。此代码在初始反转时前进(黑色变为白色,白色变为黑色等)。但是,当我拍摄倒置的图像文件并通过此代码重新运行以尝试获取原始图像时,这些值远不及原始图像,并且图像具有随机暗片和非常高的对比度。

那么告诉我,有什么更好的方法来反演倒置?以下代码是否需要调整?还有另一种方法可以解决这个问题吗?

代码:

//bitsStored is the bit depth. In this test, it is 10.
//imageBytes is the pixel data in a byte array
public static short[] invert(int bitsStored) {
    short min = min(imageBytes);//custom method. Gets the minimum value in the byte array. 
    short range = (short) (2 << bitsStored);
    short[] holder = new short[imageBytes.length];
    for (int i = 0; i < imageBytes.length; i++) {
        holder[i] = (short) (range - imageBytes[i] - min);
    }
    imageBytes = holder;
    return imageBytes;
}

注意:我正在使用的图像具有16位深度,但仅使用10位进行存储。

如果有任何方法可以让我的问题更清楚,请告诉我。谢谢!

编辑:我有个主意。可能会发生这种情况,因为最小值在第一次运行和第二次运行之间变化?我觉得,在概念上,反演的反演应该是原始的。但在数学中,两次运行之间唯一相同的数字是范围值。所以必须有一个更好的方法来做到这一点。我会继续思考它,但是你们对它的任何见解都会非常感激。

0 个答案:

没有答案